[cfe-dev] Fwd: [cfe-users] Questionable dereference of null pointer warning

Morrell, Michael michael.morrell at intel.com
Mon Feb 4 11:31:15 PST 2013


I haven't received any response yet, so I figured I'd try cfe-dev.

  Michael

Begin forwarded message:

From: "Morrell, Michael" <michael.morrell at intel.com<mailto:michael.morrell at intel.com>>
Subject: [cfe-users] Questionable dereference of null pointer warning
Date: January 31, 2013 11:09:38 AM PST
To: "cfe-users at cs.uiuc.edu<mailto:cfe-users at cs.uiuc.edu>" <cfe-users at cs.uiuc.edu<mailto:cfe-users at cs.uiuc.edu>>

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
_______________________________________________
cfe-users mailing list
cfe-users at cs.uiuc.edu<mailto:cfe-users at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users





More information about the cfe-dev mailing list