NetBSD Problem Report #41890

From www@NetBSD.org  Fri Aug 14 12:37:53 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id D2A1963C285
	for <gnats-bugs@gnats.netbsd.org>; Fri, 14 Aug 2009 12:37:52 +0000 (UTC)
Message-Id: <20090814123752.97C5B63C284@www.NetBSD.org>
Date: Fri, 14 Aug 2009 12:37:52 +0000 (UTC)
From: ebb9@byu.net
Reply-To: ebb9@byu.net
To: gnats-bugs@NetBSD.org
Subject: NULL is improperly defined
X-Send-Pr-Version: www-1.0

>Number:         41890
>Category:       standards
>Synopsis:       NULL is improperly defined
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    standards-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 14 12:40:00 +0000 2009
>Closed-Date:    Tue Oct 13 17:20:38 +0000 2009
>Last-Modified:  Sun Mar 21 03:50:02 +0000 2010
>Originator:     Eric Blake
>Release:        1.6
>Organization:
N/A
>Environment:
NetBSD netbsd 1.6 NetBSD 1.6 (GENERIC) #0: Sun Sep  8 19:43:40 UTC 2002     autobuild@tgm.daemon.org:/autobuild/i386/OBJ/autobuild/src/sys/arch/i386/compile/GENERIC i386

>Description:
NetBSD's definition of NULL as '(void *)0' falls foul of the POSIX rule that object-like macros can be used in arbitrary expressions.  I have confirmed the bug on an older release (as that is the only NetBSD machine I have access to), but the problem apparently still exists in NetBSD 5.0, as documented here:

https://savannah.gnu.org/support/?106973

The fix is to use '#define NULL ((void *) 0)' in /usr/include/sys/null.h; by properly parenthesizing NULL, then arbitrary expressions like:

sizeof NULL

will no longer cause compile errors.

>How-To-Repeat:
On the (older) machine that I have access to, I needed to define __AUDIT__ to expose the invalid definition of NULL; but apparently, newer NetBSD headers include the cast automatically (POSIX 2008 requires that NULL be defined with the cast to void*, so this is actually a good thing; it's just that you didn't go far enough by failing to properly parenthesize the result).

$ cat <<\EOF > foo.c
> #include <stddef.h>
> int main () { return sizeof NULL; }
> EOF
$ c89 -o foo foo.c
$ c89 -D__AUDIT__=1 -o foo foo.c
foo.c: In function `main':
foo.c:2: parse error before `0'

>Fix:
Properly parenthesize the definition of NULL.

>Release-Note:

>Audit-Trail:
From: David Laight <dsl@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41890 CVS commit: src/sys/sys
Date: Tue, 13 Oct 2009 17:19:01 +0000

 Module Name:	src
 Committed By:	dsl
 Date:		Tue Oct 13 17:19:00 UTC 2009

 Modified Files:
 	src/sys/sys: null.h

 Log Message:
 Enclose (void *)0 in an extra set of parenthese to make the result usable
 in arbitrary expressions.
 Fixes PR/41890, I can't think of any downsides!


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.8 src/sys/sys/null.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dsl@NetBSD.org
State-Changed-When: Tue, 13 Oct 2009 17:20:38 +0000
State-Changed-Why:
Change applied.


From: Soren Jacobsen <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41890 CVS commit: [netbsd-5] src/sys/sys
Date: Sun, 21 Mar 2010 03:45:33 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Sun Mar 21 03:45:33 UTC 2010

 Modified Files:
 	src/sys/sys [netbsd-5]: null.h

 Log Message:
 Pull up following revision(s) (requested by joerg in ticket #1344):
 	sys/sys/null.h: revision 1.8
 Enclose (void *)0 in an extra set of parenthese to make the result usable
 in arbitrary expressions.
 Fixes PR/41890, I can't think of any downsides!


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.7.86.1 src/sys/sys/null.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.