[cfe-users] Questionable dereference of null pointer warning
Morrell, Michael
michael.morrell at intel.com
Thu Jan 31 11:09:38 PST 2013
I'm getting a "dereference of null pointer" warning from the Clang static analyzer (checker-270 on MacOS) that I don't understand. A simplified example is:
=========================
void set_x1(int *&);
void set_x2(void *&);
int foo(void)
{
int *x = 0, *y = 0;
set_x1(x);
set_x2((void *&)y);
return *x + *y;
}
=========================
When I run "scan-build c++ -c" on this file, it complains about the dereference of y, but not x. Should there be a difference between these two cases?
On a related note, it appears that the analyzer assumes that a function like set_x1 will always set the argument to a non-NULL value (presumably unless it can see the source and know otherwise). Is that the best assumption and are such assumptions made by the analyzer documented anywhere?
Thanks,
Michael
More information about the cfe-users
mailing list