I checked my project with cppcheck and got the Uninitialized variable: port.isActive [uninitvar] error. This is my function code
// 0 Unknow 1 Not available 2 Available if (port.available == 2 || port.available == 0) { port.portId = jPort["Name"].toString(); port.portName = jPort["Description"].toString(); port.cardId = cardId; port.cardName = cardName; // 只添加输入port if (port.isInputPort()) { m_availableInputPorts.insert(port.portId, port); //qDebug() << " " << port; } }
This is my struct code
struct Port { QString portId; QString portName; QString cardName; int available {1}; int cardId; bool isActive {false}; bool isInputPort() const; bool isLoopback() const; };
I have already initialized the structure whi is this error still report,is it a false alarm?
Which version do you use? How is the variable portdefined in your code? I don't get a warning with current head for
port
struct S { int i{ 1 }; bool b{ false }; }; void f() { S s; if (s.i == 2 || s.b) {} }
I am using cppcheck version 2.7 and isAative is a field in the Port structure,but it's not used in this function.
Can you provide a small code example that reproduce the problem? The code CHR tried didn't reproduce the problem.
Probably it's easiest that you reduce your real code. If the code is pointless etc does not matter it's just important that we can reproduce the FP.
I think it's likely that there is a detail in your code that confuses Cppcheck somehow. And that detail is very difficult to guess.
Thank you,I understand
Log in to post a comment.
I checked my project with cppcheck and got the Uninitialized variable: port.isActive [uninitvar] error.
This is my function code
This is my struct code
I have already initialized the structure whi is this error still report,is it a false alarm?
Which version do you use? How is the variable
port
defined in your code?I don't get a warning with current head for
I am using cppcheck version 2.7 and isAative is a field in the Port structure,but it's not used in this function.
I am using cppcheck version 2.7 and isAative is a field in the Port structure,but it's not used in this function.
Can you provide a small code example that reproduce the problem? The code CHR tried didn't reproduce the problem.
Probably it's easiest that you reduce your real code. If the code is pointless etc does not matter it's just important that we can reproduce the FP.
I think it's likely that there is a detail in your code that confuses Cppcheck somehow. And that detail is very difficult to guess.
Last edit: Daniel Marjamäki 2022-04-09
Thank you,I understand