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.
This commit is contained in:
Eric Blake 2007-09-17 20:14:29 +00:00
parent 8e34786463
commit ba21046d03
2 changed files with 18 additions and 5 deletions

View 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> 2007-09-07 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/sys/_types.h: Protect all types with flag * libc/include/sys/_types.h: Protect all types with flag
@ -44,11 +50,11 @@
2007-08-31 Antony King <antony.king@st.com> 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). bits and redefine associated dword0 macro (rvalue issue).
* libc/stdio/vfieeefp.h: Ditto. * libc/stdio/vfieeefp.h: Ditto.
* libc/stdlib/strtod.c: Add checks for _DOUBLE_IS_32BITS * libc/stdlib/strtod.c: Add checks for _DOUBLE_IS_32BITS
to prevent setting dword1 which is an rvalue only. to prevent setting dword1 which is an rvalue only.
2007-08-28 Hans Kester <hans.kester@ellips.nl> 2007-08-28 Hans Kester <hans.kester@ellips.nl>

View File

@ -1029,10 +1029,17 @@ reswitch: switch (ch) {
case 'S': case 'S':
#endif #endif
sign = '\0'; 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)"; cp = "(null)";
size = 6; size = ((unsigned) prec > 6U) ? 6 : prec;
} }
#endif /* __OPTIMIZE_SIZE__ */
#ifdef _MB_CAPABLE #ifdef _MB_CAPABLE
else if (ch == 'S' || (flags & LONGINT)) { else if (ch == 'S' || (flags & LONGINT)) {
mbstate_t ps; mbstate_t ps;