When Cppcheck runs this code, [1] it complains about the error :
void bool_express(bool aPre, bool aX, bool aPost) { bool x; const bool pre = aPre; if (pre) { x = aX; } const bool post = aPost; // error checking passage of the original code: if ( !pre || !x || !post ) { if ( !pre ) { trace("pre failed"); } else if ( !x ) { // <-- HERE Cppcheck complains trace("x failed"); } else { trace("post failed"); } } else { // success passage of the original code: trace("ok"); } }
This is the message that makes me nervous:
Id: uninitvar Summary: Uninitialized variable: x Message: Uninitialized variable: x
I think this is a false positive, but I admit that this may not be obvious. However, I do not want to touch this code because it is old and much heavier than this extracted version.
Have you ever encountered similar situations? How to deal with this?
[1] This code comes down to its bones, the source code sets the precondition ( pre ), does something ( x ), then forces the postcondition ( post ), after which some error conditions are checked. I converted the results of the execution of the functions that are called and then stored in pre , x and post in 3 arguments of my test case.
c ++ cppcheck false-positive
Wolf Aug 08 '16 at 13:03 2016-08-08 13:03
source share