Test-case (tested with cppcheck v2.8.2 as well as main branch commit 5477130):
v2.8.2
main
commit 5477130
int f(void) { if (0) *(int *)0 = 1; return 0 ? *(int *)0 : 1; }
This raises the following warnings:
$ ./cppcheck /tmp/test.c Checking /tmp/test.c ... /tmp/test.c:5:4: error: Null pointer dereference: (int*)0 [nullPointer] *(int *)0 = 1; ^ /tmp/test.c:6:14: error: Null pointer dereference: (int*)0 [nullPointer] return 0 ? *(int *)0 : 1; ^
Use-case: this false positive was detected when used on a macro which takes an optional pointer. Something along the lines of:
#define optional_ret(X) do { \ /* do stuff */ \ (X) ? (*(int *)(X) = 5) : 0; \ } while (0) void f2(void) { optional_ret(NULL); }
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11311
Log in to post a comment.
Test-case (tested with cppcheck
v2.8.2
as well asmain
branchcommit 5477130
):This raises the following warnings:
Use-case: this false positive was detected when used on a macro which takes an optional pointer. Something along the lines of:
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11311