introduce in_macro() which returns true if we're in a macro
commitbc2902b7001f0d6e5cd02bd7811514427196ff2d
authorDan Carpenter <error27@gmail.com>
Tue, 27 Apr 2010 09:37:54 +0000 (27 11:37 +0200)
committerDan Carpenter <error27@gmail.com>
Tue, 27 Apr 2010 09:37:54 +0000 (27 11:37 +0200)
tree9470357d7a2a704c93ea54b84ba24c3a849cde87
parent0ddaa8f10faa709782882dde31e1d68a0156fef1
introduce in_macro() which returns true if we're in a macro

The check_null_deref.c script generates a lot of false positives because
it assumes that if we check a variable for NULL, it potentially is NULL.
That doesn't work because some macros check variables for NULL when the
context doesn't mean they are potentially NULL.  The in_macro() lets us
ignore checks inside of macros.

The in_macro() relies on the fact that positions for all the statements in
a macro are the same.  It checks the previous statement and the next
statement and if either is in the same position as the current statement
it returns true.

The in_macro() function misses some things.  The one that I know about is
if you have a single select statement like this:

#define foo(x) (x ? x->xxx : NULL)

I tried to use the big expression stack, but the problem is that we put
fake expressions on the stack in smatch_conditions.h and there is no easy
way to get the next expression.

Signed-off-by: Dan Carpenter <error27@gmail.com>
smatch.h
smatch_flow.c
smatch_helper.c