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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Samuel Vinson on 9/15/2007 6:34 AM:
> 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)

OK, I see what you are complaining about (this was the first time you
explicitly mentioned the case where precision is less than 6).  Indeed, as
long as newlib is providing an extension for a replacement string for
NULL, it should take precision into account.  Jeff, okay to apply this
patch?  [However, I still maintain that your code has a bug for expecting
any sane behavior when passing a NULL argument for %s.]

2007-09-15  Eric Blake  <ebb9@byu.net>

	* libc/stdio/vfprintf.c (_VFPRINTF_R): Take precision into account
	for %s on NULL.  Skip NULL check when optimizing for size.

- --
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

iD8DBQFG6+u284KuGfSFAYARApoRAJ9xgjM2EC8Ha9qGwwPLOLP9xwg3ngCaAt8H
dyartGnGWzIOZpmy39Kh0UU=
=zDW1
-----END PGP SIGNATURE-----
Index: libc/stdio/vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.65
diff -u -p -r1.65 vfprintf.c
--- libc/stdio/vfprintf.c	19 Jul 2007 03:42:21 -0000	1.65
+++ libc/stdio/vfprintf.c	15 Sep 2007 14:22:54 -0000
@@ -1029,10 +1029,20 @@ reswitch:	switch (ch) {
 		case 'S':
 #endif
 			sign = '\0';
-			if ((cp = GET_ARG (N, ap, char_ptr_t)) == NULL) {
+			cp = GET_ARG (N, ap, char_ptr_t);
+#ifndef __OPTIMIZE_SIZE__
+			/* Behavior is undefined if the user passed a
+			   NULL string.  However, if we are not
+			   optimizing for size, we might as well
+			   mirror glibc behavior.  */
+			if (cp == NULL) {
 				cp = "(null)";
-				size = 6;
+				if (prec == -1 || prec > 6)
+					size = 6;
+				else
+					size = prec;
 			}
+#endif
 #ifdef _MB_CAPABLE
 			else if (ch == 'S' || (flags & LONGINT)) {
 				mbstate_t ps;

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