The value of Ret is conditionally overwritten, so the second check for Ret != 0 is not always true.
long GetRet(); long foo(long N) { for (long I = 0; I < N; I++) { long Ret = GetRet(); if (Ret != 0) { if (Ret == 1) Ret = GetRet(); if (Ret != 0) // style: Condition 'Ret!=0' is always true [knownConditionTrueFalse] break; } } return Ret; }
Thanks! I can reproduce. I have created ticket https://trac.cppcheck.net/ticket/9893
Thanks for your response. This one is probably related:
bool cond(); long bar() { bool stop = false; while (!stop) { if (cond()) stop = true; break; } if (!stop) return 1; return 0; }
Thanks! I can reproduce. I created ticket https://trac.cppcheck.net/ticket/9894
Another instance:
long GetN(); bool cond(); void calc(long& N); long baz() { long N = GetN(); if (N == 0) return 0; if (N > 1) // note that cond() does not trigger the warning calc(N); if (N == 0) return 0; return N + 1; }
Thanks! I can reproduce. I created ticket https://trac.cppcheck.net/ticket/9895
Log in to post a comment.
The value of Ret is conditionally overwritten, so the second check for Ret != 0 is not always true.
Thanks! I can reproduce. I have created ticket https://trac.cppcheck.net/ticket/9893
Thanks for your response. This one is probably related:
Thanks! I can reproduce. I created ticket https://trac.cppcheck.net/ticket/9894
Another instance:
Last edit: CHR 2020-09-11
Thanks! I can reproduce. I created ticket https://trac.cppcheck.net/ticket/9895