Hello cppcheck community,
Using cppcheck 2.3, I found that cppcheck can generate a false positive (knownConditionTrueFalse) when a volatile variable is checked in a branch condition. Consider the following example:
#include <stdio.h> #include <signal.h> static volatile sig_atomic_t is_running; static void handler(int signum) { is_running = 0; } int main(void) { signal(SIGINT, &handler); is_running = 1; while (is_running) {} printf("Interrupted!\n"); return 0; }
When run with the --enable=all option, cppcheck generates the following warning:
--enable=all
example.c:13:12: style: Condition 'is_running' is always true [knownConditionTrueFalse] while (is_running) {} ^
Thank you for your attention in this matter.
Thanks! I can reproduce. I created https://trac.cppcheck.net/ticket/10223
Log in to post a comment.
Hello cppcheck community,
Using cppcheck 2.3, I found that cppcheck can generate a false positive (knownConditionTrueFalse) when a volatile variable is checked in a branch condition. Consider the following example:
When run with the
--enable=all
option, cppcheck generates the following warning:Thank you for your attention in this matter.
Thanks! I can reproduce. I created https://trac.cppcheck.net/ticket/10223