cppcheck - stumbling upon a non-trivial bool scenario in C++ -


when cppcheck runs on code,[1] complains 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 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 original code:         trace("ok");     } } 

this message, makes me nervous:

id: uninitvar summary: uninitialized variable: x message: uninitialized variable: x 

i think it's false positive, admit may not obvious. nevertheless don't want touch code, because it's old , lot heavier extracted version.

have ever experienced situations this? how deal it?


[1] code reduced bones, original code establishes precondition (pre), (x), forces postcondition (post), after that, error conditions checked. transformed runtime-results of functions called , stored in pre, x, , post 3 arguments of test case.

it false positive in cppcheck. solved adding inline suppression:[1]

    if ( !pre ) {         trace("pre failed");     // cppcheck-suppress uninitvar     } else if ( !x ) {         trace("x failed");     } else {         trace("post failed");     } 

and brought attention of cppcheck developers:

#7663 (false positive: uninitialised variable in unreachable code)


[1] decided not initialize variable. not performance reasons, informed bug being fixed in future release, when cppcheck say

id: unmatchedsuppression summary: unmatched suppression: uninitvar message: unmatched suppression: uninitvar 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -