-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Any objections to this patch? I know that Solaris 10 still uses the following, which meets C99 and POSIX 2001 but is non-compliant with POSIX 2008:
#ifndef NULL #if defined(_LP64) #define NULL 0L #else #define NULL 0 #endif #endif But I can't think of any valid C construct that can distinguish between an integral '0' and '((void*)0)' without causing compilation errors. And since most modern machines use all 0 bits as the null pointer, passing a correctly sized integral constant through varags (as in Solaris) is indistinguishable from passing (void*) cast. About the only other thing I can think of where a missing cast makes a difference is places where the gcc __attribute__((sentinel)) takes effect (it warns if the cast is missing, even if the integral constant is the correct size), but installing gcc also installs a fixincludes for NULL for this very reason. Thus, even though Solaris cc still sees a non-POSIX definition of NULL, gcc on Solaris sees ((void*)0) and the sentinel warning does not trigger for this code: execlp ("foo", "foo", NULL); But if anyone can think of any other test we can use to ensure that NULL can always be safely used without extra casts as an argument to a varargs function, I'm all ears. If nothing else, this patch will help us sniff out if there are any platforms in the wild that define NULL to the wrong size integral 0. - -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpE5cgACgkQ84KuGfSFAYB/6ACfcX6TtxsphPNmFCcuT0bmF/Sn hO0An0gEid8/Y+PYybkgqsH0UZrG2Wuf =4/S8 -----END PGP SIGNATURE-----
>From e1acffdc5d7765b74fec126287b7f4c9de2c7023 Mon Sep 17 00:00:00 2001 From: Eric Blake <e...@byu.net> Date: Fri, 26 Jun 2009 08:00:28 -0600 Subject: [PATCH] tests: add test for bogus NULL definition * tests/test-stdio.c: Ensure POSIX 2008 requirement on NULL. * tests/test-stdlib.c: Likewise. * tests/test-string.c: Likewise. * tests/test-locale.c: Likewise. * tests/test-unistd.c: Likewise. * modules/stdio-tests (Depends-on): Add verify. * modules/stdlib-tests (Depends-on): Likewise. * modules/string-tests (Depends-on): Likewise. * modules/locale-tests (Depends-on): Likewise. * modules/unistd-tests (Depends-on): Likewise. Signed-off-by: Eric Blake <e...@byu.net> --- ChangeLog | 14 ++++++++++++++ modules/locale-tests | 1 + modules/stdio-tests | 1 + modules/stdlib-tests | 1 + modules/string-tests | 1 + modules/unistd-tests | 1 + tests/test-locale.c | 8 +++++++- tests/test-stdio.c | 8 +++++++- tests/test-stdlib.c | 8 +++++++- tests/test-string.c | 8 +++++++- tests/test-unistd.c | 6 ++++++ 11 files changed, 53 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e5fdb1..573091f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-06-26 Eric Blake <e...@byu.net> + + tests: add test for bogus NULL definition + * tests/test-stdio.c: Ensure POSIX 2008 requirement on NULL. + * tests/test-stdlib.c: Likewise. + * tests/test-string.c: Likewise. + * tests/test-locale.c: Likewise. + * tests/test-unistd.c: Likewise. + * modules/stdio-tests (Depends-on): Add verify. + * modules/stdlib-tests (Depends-on): Likewise. + * modules/string-tests (Depends-on): Likewise. + * modules/locale-tests (Depends-on): Likewise. + * modules/unistd-tests (Depends-on): Likewise. + 2009-06-25 Eric Blake <e...@byu.net> version-etc: fix regression diff --git a/modules/locale-tests b/modules/locale-tests index 3a5fa87..19bc373 100644 --- a/modules/locale-tests +++ b/modules/locale-tests @@ -2,6 +2,7 @@ Files: tests/test-locale.c Depends-on: +verify configure.ac: diff --git a/modules/stdio-tests b/modules/stdio-tests index cc0f14e..c572bfb 100644 --- a/modules/stdio-tests +++ b/modules/stdio-tests @@ -2,6 +2,7 @@ Files: tests/test-stdio.c Depends-on: +verify configure.ac: diff --git a/modules/stdlib-tests b/modules/stdlib-tests index 8a5a78f..3503511 100644 --- a/modules/stdlib-tests +++ b/modules/stdlib-tests @@ -2,6 +2,7 @@ Files: tests/test-stdlib.c Depends-on: +verify configure.ac: diff --git a/modules/string-tests b/modules/string-tests index 67d08bb..ab8699a 100644 --- a/modules/string-tests +++ b/modules/string-tests @@ -2,6 +2,7 @@ Files: tests/test-string.c Depends-on: +verify configure.ac: diff --git a/modules/unistd-tests b/modules/unistd-tests index 703d557..7f9d44d 100644 --- a/modules/unistd-tests +++ b/modules/unistd-tests @@ -2,6 +2,7 @@ Files: tests/test-unistd.c Depends-on: +verify configure.ac: diff --git a/tests/test-locale.c b/tests/test-locale.c index 39e7de9..625cc43 100644 --- a/tests/test-locale.c +++ b/tests/test-locale.c @@ -1,5 +1,5 @@ /* Test of <locale.h> substitute. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,6 +20,8 @@ #include <locale.h> +#include "verify.h" + int a[] = { LC_ALL, @@ -31,6 +33,10 @@ int a[] = LC_TIME }; +/* Check that NULL can be passed through varargs as a pointer type, + per POSIX 2008. */ +verify (sizeof NULL == sizeof (void *)); + int main () { diff --git a/tests/test-stdio.c b/tests/test-stdio.c index a5efa32..dcfe38d 100644 --- a/tests/test-stdio.c +++ b/tests/test-stdio.c @@ -1,5 +1,5 @@ /* Test of <stdio.h> substitute. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,9 +20,15 @@ #include <stdio.h> +#include "verify.h" + /* Check that the various SEEK_* macros are defined. */ int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET }; +/* Check that NULL can be passed through varargs as a pointer type, + per POSIX 2008. */ +verify (sizeof NULL == sizeof (void *)); + int main () { diff --git a/tests/test-stdlib.c b/tests/test-stdlib.c index e103d46..ae46ba1 100644 --- a/tests/test-stdlib.c +++ b/tests/test-stdlib.c @@ -1,5 +1,5 @@ /* Test of <stdlib.h> substitute. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,8 +20,14 @@ #include <stdlib.h> +#include "verify.h" + int exitcode; +/* Check that NULL can be passed through varargs as a pointer type, + per POSIX 2008. */ +verify (sizeof NULL == sizeof (void *)); + int main () { diff --git a/tests/test-string.c b/tests/test-string.c index 68014f5..fe53cd9 100644 --- a/tests/test-string.c +++ b/tests/test-string.c @@ -1,5 +1,5 @@ /* Test of <string.h> substitute. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,6 +20,12 @@ #include <string.h> +#include "verify.h" + +/* Check that NULL can be passed through varargs as a pointer type, + per POSIX 2008. */ +verify (sizeof NULL == sizeof (void *)); + int main () { diff --git a/tests/test-unistd.c b/tests/test-unistd.c index 5fed15c..129367b 100644 --- a/tests/test-unistd.c +++ b/tests/test-unistd.c @@ -20,6 +20,12 @@ #include <unistd.h> +#include "verify.h" + +/* Check that NULL can be passed through varargs as a pointer type, + per POSIX 2008. */ +verify (sizeof NULL == sizeof (void *)); + /* Check that the various SEEK_* macros are defined. */ int sk[] = { SEEK_CUR, SEEK_END, SEEK_SET }; -- 1.6.3.3.334.g916e1