From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 11 13:11:23 2012 Return-Path: Delivered-To: hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A92486CD for ; Thu, 11 Oct 2012 13:11:23 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 00B648FC12 for ; Thu, 11 Oct 2012 13:11:21 +0000 (UTC) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id QAA03299; Thu, 11 Oct 2012 16:11:18 +0300 (EEST) (envelope-from avg@FreeBSD.org) Message-ID: <5076C576.3020306@FreeBSD.org> Date: Thu, 11 Oct 2012 16:11:18 +0300 From: Andriy Gapon User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1 MIME-Version: 1.0 To: Erik Cederstrand Subject: Re: curcpu false positive? References: <3A22DF7A-00BB-408C-8F76-C1E119E0E48C@cederstrand.dk> In-Reply-To: <3A22DF7A-00BB-408C-8F76-C1E119E0E48C@cederstrand.dk> X-Enigmail-Version: 1.4.3 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Oct 2012 13:11:23 -0000 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