]> sourceware.org Git - newlib-cygwin.git/commitdiff
Obey POSIX on printf("%.s", (char*)NULL).
authorEric Blake <eblake@redhat.com>
Mon, 17 Sep 2007 20:14:29 +0000 (20:14 +0000)
committerEric Blake <eblake@redhat.com>
Mon, 17 Sep 2007 20:14:29 +0000 (20:14 +0000)
* libc/stdio/vfprintf.c (_VFPRINTF_R): Take precision into account
for %s on NULL.  Skip NULL check when optimizing for size.

newlib/ChangeLog
newlib/libc/stdio/vfprintf.c

index 97d4228fb4f154cd1abb078f63c0a615a62a7ea2..f35dc5d455e2e58a5611074d355ab7acaa062cb5 100644 (file)
@@ -1,3 +1,9 @@
+2007-09-17  Eric Blake  <ebb9@byu.net>
+
+       Obey POSIX on printf("%.s", (char*)NULL).
+       * libc/stdio/vfprintf.c (_VFPRINTF_R): Take precision into account
+       for %s on NULL.  Skip NULL check when optimizing for size.
+
 2007-09-07  Jeff Johnston  <jjohnstn@redhat.com>
 
        * libc/include/sys/_types.h: Protect all types with flag
 
 2007-08-31  Antony King  <antony.king@st.com>
 
-        * libc/stdlib/mprec.h [_DOUBLE_IS_32BITS}: Define IEEE_Arith
+       * libc/stdlib/mprec.h [_DOUBLE_IS_32BITS}: Define IEEE_Arith
        bits and redefine associated dword0 macro (rvalue issue).
        * libc/stdio/vfieeefp.h: Ditto.
-        * libc/stdlib/strtod.c: Add checks for _DOUBLE_IS_32BITS
-        to prevent setting dword1 which is an rvalue only.
+       * libc/stdlib/strtod.c: Add checks for _DOUBLE_IS_32BITS
+       to prevent setting dword1 which is an rvalue only.
 
 2007-08-28  Hans Kester  <hans.kester@ellips.nl>
 
index 491369012b223322b752ab95f8ded4743bb52835..44d46f20c2880fb7d76c9edd240678ee82b38b08 100644 (file)
@@ -1029,10 +1029,17 @@ 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 when precision is not 0.
+                          However, if we are not optimizing for size,
+                          we might as well mirror glibc behavior.  */
+                       if (cp == NULL) {
                                cp = "(null)";
-                               size = 6;
+                               size = ((unsigned) prec > 6U) ? 6 : prec;
                        }
+#endif /* __OPTIMIZE_SIZE__ */
 #ifdef _MB_CAPABLE
                        else if (ch == 'S' || (flags & LONGINT)) {
                                mbstate_t ps;
This page took 0.05286 seconds and 5 git commands to generate.