Bug in _VFPRINTF_R

Samuel Vinson samuelv@laposte.net
Sat Sep 15 11:52:00 GMT 2007


Hi,

In newlib printf, snprintf (perhaps others string functions) use 
_VFPRINTF_R.
So if you call :   
    printf("%.*s\n",len,(char *)NULL)   
    snprintf(ptr, 40, "%.*s", len, (char *)NULL)
You obtain :
    (null)
    ptr = "(null)"

I never see that with different libc implementation, I used 
(linux/gcc/libc/glibc, windows/msvcrt, solaris/libc...)
Perhaps POSIX and C99 allow your choice, but this is not portable in 
different platforms.

Samuel

Eric Blake-1 a écrit :
>> I think there is a bug in _VFPRINTF_R (vfprintf.c) in the string case.
>>     
>
> Not a bug.
>
>   
>> I think if cp equals NULL, cp just  should be empty.
>>     
>
> Why?  POSIX and C99 are both clear - if cp is NULL, your
> program is invoking undefined behavior.  Newlib is allowed
> to do whatever it wants, including reformat your hard
> drive.  However, for debuggability purposes, we have
> instead chosen to copy glibc, and print "(null)" to point
> out your non-compliant program a little more nicely.
>
>   



More information about the Newlib mailing list