bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: c-strtod: improve error checking


From: Simon Josefsson
Subject: Re: c-strtod: improve error checking
Date: Thu, 22 Jan 2009 00:36:06 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux)

address@hidden (Peter Seebach) writes:

> In message <address@hidden>, Karl Berry writes:
>>I am surprised.  I thought 0 was supposed to be a valid null pointer in
>>all contexts, without casting.
>
> 0 is a null pointer constant.  In a context where the language anticipates
> a pointer, a null pointer constant becomes a null pointer.  This means that
> it's normally safe to write 0 and expect the language to treat it as a null
> pointer, but it's quite possible to create contexts in which it isn't:
>
>       printf("%p\n", 0);
>
> This isn't guaranteed to work, because variable argument lists aren't
> prototyped, so the compiler has no knowledge that it has to convert the 0
> into a null pointer.
>
> In other contexts, it's pretty much useless to cast 0s.  Note that NULL could
> be the same, or it could be already converted to (void *), so it depends on
> the implementation whether:
>
>       printf("%p\n", NULL);
>
> is legit.  (Which means it's not portable...)

Indeed, and a quite realistic example of where this bug hits in practice
is with the version-etc module where the final NULL needs to be
explicitly casted to work properly on all systems, e.g.:

      version_etc (stdout, "gsasl", p, gsasl_check_version (NULL),
                   "Simon Josefsson", (char *) NULL);

/Simon




reply via email to

[Prev in Thread] Current Thread [Next in Thread]