Message ID | 4A623766.5020002@ramsay1.demon.co.uk (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Sat, Jul 18, 2009 at 1:58 PM, Ramsay Jones<ramsay@ramsay1.demon.co.uk> wrote: > > These sparse warnings are caused by broken new-lib headers, > which sometimes result in NULL being defined as 0, and at > other times defined as ((void *)0). > > In essence, the only header which works correctly (by defining > NULL as ((void *)0)) is stddef.h. The stdio.h and time.h headers > also work, almost by accident, by indirectly including stddef.h. > The other standard headers which are required to define the NULL > macro, namely locale.h, stdlib.h, string.h and wchar.h, all > define the macro as the 0 token. (This is a slightly simplified > description of the problem). > > In order to suppress these warnings, include the stddef.h header > at the start of ptrlist.c. > > Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> > --- > > Hi Chris, > > $ cat -n null-test.sh > Â Â 1 Â #!/bin/bash > Â Â 2 > Â Â 3 Â # The C99 standard says that the following headers define NULL: > Â Â 4 Â # Â locale.h (7.11), stddef.h (7.17), stdio.h (7.19.1), > Â Â 5 Â # Â stdlib.h (7.20), string.h (7.21.1), time.h (7.23.1), > Â Â 6 Â # Â wchar.h (7.24.1). > Â Â 7 > Â Â 8 Â for i in locale.h stddef.h stdio.h stdlib.h string.h time.h wchar.h > Â Â 9 Â do > Â Â 10 Â Â Â Â Â printf "%10s: Â " $i > Â Â 11 Â Â Â Â Â printf "#include<%s>\nchar *xyz_ptr = NULL;\n" $i >t.c > Â Â 12 Â Â Â Â Â cgcc -E t.c | grep xyz_ptr > Â Â 13 Â done > Â Â 14 Â rm t.c > Â Â 15 > $ ./null-test.sh That is what I get in FC11: locale.h: char *xyz_ptr = ((void *)0); stddef.h: char *xyz_ptr = ((void *)0); stdio.h: char *xyz_ptr = ((void *)0); stdlib.h: char *xyz_ptr = ((void *)0); string.h: char *xyz_ptr = ((void *)0); time.h: char *xyz_ptr = ((void *)0); wchar.h: char *xyz_ptr = ((void *)0); Which system has this problem? Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Christopher Li wrote: > On Sat, Jul 18, 2009 at 1:58 PM, Ramsay Jones<ramsay@ramsay1.demon.co.uk> wrote: [snip] >> >> $ cat -n null-test.sh >> 1 #!/bin/bash >> 2 >> 3 # The C99 standard says that the following headers define NULL: >> 4 # locale.h (7.11), stddef.h (7.17), stdio.h (7.19.1), >> 5 # stdlib.h (7.20), string.h (7.21.1), time.h (7.23.1), >> 6 # wchar.h (7.24.1). >> 7 >> 8 for i in locale.h stddef.h stdio.h stdlib.h string.h time.h wchar.h >> 9 do >> 10 printf "%10s: " $i >> 11 printf "#include<%s>\nchar *xyz_ptr = NULL;\n" $i >t.c >> 12 cgcc -E t.c | grep xyz_ptr >> 13 done >> 14 rm t.c >> 15 >> $ ./null-test.sh > > That is what I get in FC11: > locale.h: char *xyz_ptr = ((void *)0); > stddef.h: char *xyz_ptr = ((void *)0); > stdio.h: char *xyz_ptr = ((void *)0); > stdlib.h: char *xyz_ptr = ((void *)0); > string.h: char *xyz_ptr = ((void *)0); > time.h: char *xyz_ptr = ((void *)0); > wchar.h: char *xyz_ptr = ((void *)0); > > Which system has this problem? > This is on cygwin. (as mentioned in the subject;P) ATB, Ramsay Jones -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 21, 2009 at 2:54 PM, Ramsay Jones<ramsay@ramsay1.demon.co.uk> wrote:
> This is on cygwin. (as mentioned in the subject;P)
Sorry I miss the most obvious spot :-). Let me take a look.
Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/ptrlist.c b/ptrlist.c index 2620412..7d18862 100644 --- a/ptrlist.c +++ b/ptrlist.c @@ -5,6 +5,7 @@ * * (C) Copyright Linus Torvalds 2003-2005 */ +#include <stddef.h> #include <stdlib.h> #include <string.h> #include <assert.h>
These sparse warnings are caused by broken new-lib headers, which sometimes result in NULL being defined as 0, and at other times defined as ((void *)0). In essence, the only header which works correctly (by defining NULL as ((void *)0)) is stddef.h. The stdio.h and time.h headers also work, almost by accident, by indirectly including stddef.h. The other standard headers which are required to define the NULL macro, namely locale.h, stdlib.h, string.h and wchar.h, all define the macro as the 0 token. (This is a slightly simplified description of the problem). In order to suppress these warnings, include the stddef.h header at the start of ptrlist.c. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> --- Hi Chris, $ cat -n null-test.sh 1 #!/bin/bash 2 3 # The C99 standard says that the following headers define NULL: 4 # locale.h (7.11), stddef.h (7.17), stdio.h (7.19.1), 5 # stdlib.h (7.20), string.h (7.21.1), time.h (7.23.1), 6 # wchar.h (7.24.1). 7 8 for i in locale.h stddef.h stdio.h stdlib.h string.h time.h wchar.h 9 do 10 printf "%10s: " $i 11 printf "#include<%s>\nchar *xyz_ptr = NULL;\n" $i >t.c 12 cgcc -E t.c | grep xyz_ptr 13 done 14 rm t.c 15 $ ./null-test.sh locale.h: char *xyz_ptr = 0; stddef.h: char *xyz_ptr = ((void *)0); stdio.h: char *xyz_ptr = ((void *)0); stdlib.h: char *xyz_ptr = 0; string.h: char *xyz_ptr = 0; time.h: char *xyz_ptr = ((void *)0); wchar.h: char *xyz_ptr = 0; $ The "slightly simplified" description above deliberately omits details which I'm happy to illuminate if necessary; but it's not very interesting! This is clearly not a sparse bug, but it is a simple solution to remove the sparse warnings. Having said that, it would be good if sparse could notice that the pre-processed source text included the NULL token, *not* the 0 token, and not issue this warning at all. ;-) ATB, Ramsay Jones ptrlist.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)