While the warning has some merit for the sample program (because the condition is indeed redundant as it can never be satisfied), it is confusing for similar code using post-incrementation: struct s foo = { 0 }; foo.array[foo.index++] = 1; if (foo.index == 1) { ... } In this case, neither the condition is redundant nor the array is accessed out of bounds.
Hi there, Thank you again for your work on cppcheck! For the following C program: struct s { int array[1]; int index; }; int main(void) { struct s foo = { 0 }; foo.array[foo.index] = 1; if (foo.index == 1) { return foo.index; } return 0; } cppcheck 2.4.1 (with --enable=warning) reports: Checking test.c ... test.c:8:11: warning: Either the condition 'foo.index==1' is redundant or the array 'foo.array[1]' is accessed at index 1, which is out of bounds. [arrayIndexOutOfBoundsCond] foo.array[foo.index]...
Hi there, Thank you for your work on cppcheck! For the following C program: int main(int argc, char *argv[]) { int quotient, remainder; remainder = argc % 2; argc /= 2; quotient = argc; if (quotient != 0) { return quotient; } return remainder; } cppcheck 2.3 (with --enable=warning) reports: Checking test.c ... test.c:4:19: warning: Either the condition 'quotient!=0' is redundant or there is division by zero at line 4. [zerodivcond] remainder = argc % 2; ^ test.c:8:15: note: Assuming that condition...
This issue appears to have been fixed by commit 72fa5f2e2729bc8ccf79cfb24ab4ac5a35f9faad, i.e. in cppcheck 2.2.
Hi there, Thank you for your work on cppcheck! For the following C code: struct foo { int x; }; int main(void) { struct foo bar; (&bar)->x = 1; if (bar.x == 0) { } return 0; } cppcheck 2.0 reports: Checking test.c ... test.c:8:10: error: Uninitialized variable: x [uninitvar] if (bar.x == 0) { } ^ Using an intermediate variable silences the warning: struct foo *baz = &bar; baz->x = 1; So does lack of indirection, of course: bar.x = 1; "git bisect" claims that commit 7368a54629a0174383cedfdb4ec5e4b73475cfa3...
Thanks! In my patch I tried hard not to call istream.available() twice for each loop...
Minor correction: in the first paragraph, I obviously meant after right-clicking...
Detached signatures for large attachments fail to verify