On 25 December 2016 at 20:41, Gert Doering <g...@greenie.muc.de> wrote:
> On Sun, Dec 25, 2016 at 08:58:23PM +0800, Antonio Quartulli wrote:
>> What is the general rule then? cron2 explained me on IRC that in the past 
>> some C
>> programs would crash when trying to print NULL, but it should not be
>> the case anymore (at least on Linux).
>
> As mentioned occasionally, we run on more than Linux.  So this is only
> safe if all supported platforms can handle
>
>   printf( "%s\n", NULL );
>
> correctly - Solaris, all the BSDs, MacOS, Windows(!), AIX.
>
> "It works on Linux" is good, but this is a "boolean and" condition - it
> needs to work on *all* supported platforms.
>
> I'm not generally opposed to modernizing the code, but the onus of
> recherching whether such a change is safe is on the proposer.

We use -std=c99, and according to C99, passing a NULL to printf()
results in undefined behaviour.  Excerpt from the C99 standard,
section 7.1.4 "Use of library functions":

"Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow: If an argument to
a function has an invalid value (such as [...] or a null pointer,
[...]) or [...], the behavior is undefined."

The section about printf() does not state otherwise.

Some, most or all platforms we support might print "(null)", but I
don't think it's wise to rely on that.  So yes, if the pointer can be
NULL, I think we should check for it.  In this case, in particular
with the (new) wrapper, I think it is simpler to just check for NULL
then to figure out if the code can ever be passed a NULL pointer.  At
least the np() wrappers that are used seem to indicate that it might
be possible.

-Steffan

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to