This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in _VFPRINTF_R


Yes you are right, I forgot to mention len = 0.
I'm sorry.

Samuel

Matt Gessner a écrit :
First, apologies because the first email I posted in response was sent before I finished editing it.

I'm sorry Eric, but I gave you a specific example :
    printf("%.*s\n",len,(char *)NULL) /* len = 0 */

and not printf("%s", (char *)NULL)


Actually, you did NOT use that as your example.


You posted:

*******************************************************************
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)"


*******************************************************************

Never did you mention anywhere that len == 0.

That drastically changes the meaning of the code you originally posted, and while I don't have the code in front of me, the len == 0 case is not going to be processed in the precise section where you originally posted your change.

FWIW, I think your suggested behaviour makes sense, for snprintf, but not for printf.

In my example, I think the result should be empty an not (null)

Samuel

Eric Blake a écrit :
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Samuel Vinson on 9/15/2007 1:35 AM:

I never see that with different libc implementation, I used
(linux/gcc/libc/glibc, windows/msvcrt, solaris/libc...)

It may not match msvcrt or solaris libc, but it does match glibc - I'm
not
sure how you tested it.


Perhaps POSIX and C99 allow your choice, but this is not portable in
different platforms.

This is not portable, period.  Calling printf("%s", (char*)NULL) invokes
undefined behavior, and is a bug in your program, not in newlib.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG68gr84KuGfSFAYARAr2PAKCR56DlvOvhKZXMeDn+ecmYO7fXEQCeMEUV
kGk4bBxoFTk2hpRD3TiakLM=
=LIb4
-----END PGP SIGNATURE-----








Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]