New cppcheck version has introduced a false positive knownConditionTrueFalse case where it incorrectly deduces that a MIN() operation is clamping a value to 0. Problem seems to be specific to unsigned variables. Reproducible: Always Steps to Reproduce: 1. Create this C file, example.c #ifndef MIN #define MIN(x, y) (((x) < (y)) ? (x) : (y)) #endif void example(unsigned int old_val) { unsigned int new_val = MIN(old_val, 65535); if (!new_val) { } } 2. Run $ cppcheck --enable=all example.c Actual Results: $ cppcheck --enable=all example.c Checking example.c ... example.c:9:6: style: Condition '!new_val' is always true [knownConditionTrueFalse] if (!new_val) { ^ example.c:7:25: note: Assignment 'new_val=((old_val)<65535)?old_val:65535', assigned value is less than 1 unsigned int new_val = MIN(old_val, 65535); ^ example.c:9:6: note: Condition '!new_val' is always true if (!new_val) { ^ example.c:5:0: style: The function 'example' is never used. [unusedFunction] void example(unsigned int old_val) ^ Active checkers: 106/565 Expected Results: Only the unusedFunction warning. The knownConditionTrueFalse warning is clearly bogus. Occurs with both the current Fedora 38 released cppcheck: $ cppcheck --version Cppcheck 2.12.0 $ rpm -q cppcheck cppcheck-2.12.0-2.fc38.x86_64 Also occurs with the update in testing: $ cppcheck --version Cppcheck 2.12.1 $ rpm -q cppcheck cppcheck-2.12.1-1.fc38.x86_64 Problem does *not* occur with the version in Fedora 38 base (not updates): $ cppcheck --version Cppcheck 2.9 $ rpm -q cppcheck cppcheck-2.9-4.fc38.x86_64
I also mentioned this on the upstream forums at: https://sourceforge.net/p/cppcheck/discussion/general/thread/f5b1a00646/ The problem still appears to be there in the latest upstream git.