[cfe-dev] New dereference pointer check

Sean McBride sean at rogue-research.com
Mon Apr 28 15:32:44 PDT 2014


On Fri, 25 Apr 2014 10:30:34 +0000, Anders Rönnholm said:

>I intend to do a new dereference check. Much like the "division by zero
>then check" check i have started on.
>
>e.g
>void foo0(int *p, int a) {
>  *p = 0;
>  if (p == 0) {}  // expected-warning {{Possible null pointer
>dereference: p - otherwise it is redundant to check it against null}}
>}
>
>I plan to do it the same way:
> 
>1. When a dereference is made store the value to the program state.
>2. When reaching a condition that checks if a value is 0, check if the
>value has been dereferenced in the same scope previously.
>3. Report bug
> 
>Is this a check you would be interested in having?

Well, I merely lurk here, but I think this would be great to have.  cppcheck does this already, and I have found it useful, often revealing a real bug, or at least a style issue.

Cheers,

Sean






More information about the cfe-dev mailing list