|
Message-ID: <20130112133343.GI20323@brightrain.aerifal.cx> Date: Sat, 12 Jan 2013 08:33:43 -0500 From: Rich Felker <dalias@...ifal.cx> To: musl@...ts.openwall.com Subject: Re: NULL On Sat, Jan 12, 2013 at 08:15:21AM +0100, Luca Barbato wrote: > On 12/01/13 07:46, Rich Felker wrote: > > On Sat, Jan 12, 2013 at 12:32:44AM -0600, Rob Landley wrote: > >> On 01/09/2013 07:36:43 AM, John Spencer wrote: > >>>> using NULL in the argument of variadic functions is ub both > >>>> in c and c++ > >>> > >>> many developers don't care about the standard. they take the stance: > >>> "works for me, if you want it patched then do it yourself and > >>> we'll eventually merge" > >> > >> Why is it UB? The standard says it's a pointer. If you pull %p off > >> in printf, feeding NULL in that slot should work fine. > > > > See my other message. NULL is not required to have pointer type. It > > can be any null pointer constant, which includes things like 0, 0L, > > 0ULL, (sizeof 1 - sizeof 2), (void *)(1ULL/2ULL), etc. > > > > The %p specifier, on the other hand, requires an argument of type void > > *; passing any other type yields UB. > > so printf("%s", NULL) would lead to UB if NULL is 0L ? printf("%s", (void *)0) leads to UB too. The %s specifier requires a pointer to a string, not a null pointer. Perhaps you meant printf("%p", NULL), and in that case yes, it could also be UB. It will _work_ if NULL is defined to 0L (since the size, representation, and argument passing convention is the same for long and pointers on all relevant systems) but it's still UB. On the other hand, it subtly breaks if NULL is simply 0, which is what this whole thread is about: whether we should work around such broken programs. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.