curcpu false positive?

2012-10-11 Thread Erik Cederstrand
Hello,

I'm looking at some Clang Static Analyzer reports in the kernel, and a lot of 
them point back to a null pointer dereference in __pcpu_type 
(sys/amd64/include/pcpu.h:102) which is defined as:

102  /*
103  * Evaluates to the type of the per-cpu variable name.
104  */
105 #define __pcpu_type(name)   
\
106 __typeof(((struct pcpu *)0)-name)


Which indeed looks like a NULL pointer dereference. Looking at the latest 
commit message there, I'm sure the code is correct, but I'm unsure why the null 
pointer is OK. I'd appreciate an explanation :-)

Thanks,
Erik
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: curcpu false positive?

2012-10-11 Thread Andriy Gapon
on 11/10/2012 16:06 Erik Cederstrand said the following:
 Hello,
 
 I'm looking at some Clang Static Analyzer reports in the kernel, and a lot of 
 them point back to a null pointer dereference in __pcpu_type 
 (sys/amd64/include/pcpu.h:102) which is defined as:
 
 102/*
 103* Evaluates to the type of the per-cpu variable name.
 104*/
 105   #define __pcpu_type(name)   
 \
 106   __typeof(((struct pcpu *)0)-name)
 
 
 Which indeed looks like a NULL pointer dereference. Looking at the latest 
 commit message there, I'm sure the code is correct, but I'm unsure why the 
 null pointer is OK. I'd appreciate an explanation :-)

Read about __typeof [1].
It's evaluated at compile time, so actual value of an expression does not matter
at all.

[1] http://gcc.gnu.org/onlinedocs/gcc/Typeof.html
-- 
Andriy Gapon
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org