diff options
author | Eric Blake <eblake@redhat.com> | 2007-09-17 20:14:29 +0000 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2007-09-17 20:14:29 +0000 |
commit | ba21046d032462b4bb1f601e0014a0306c201913 (patch) | |
tree | 77eafe281ed839a50ee99cd29fac7f6956ccafeb /newlib/libc/stdio/vfprintf.c | |
parent | 8e34786463bdb1f7725a728de408183b2870b16d (diff) | |
download | newlib-ba21046d032462b4bb1f601e0014a0306c201913.zip newlib-ba21046d032462b4bb1f601e0014a0306c201913.tar.gz newlib-ba21046d032462b4bb1f601e0014a0306c201913.tar.bz2 |
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.
Diffstat (limited to 'newlib/libc/stdio/vfprintf.c')
-rw-r--r-- | newlib/libc/stdio/vfprintf.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index 4913690..44d46f2 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -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; |