diff options
author | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-11-16 19:13:11 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-11-16 19:13:11 +0530 |
commit | 2b766585f9b4ffabeef2f36200c275976b93f2c7 (patch) | |
tree | d6be89abc6bfa88e5e9fd997bb4cfd94b035adc2 /stdio-common/vfprintf.c | |
parent | b1848fdeec705bc7d2f64e3a365f1ff66eeb4f0d (diff) | |
download | glibc-2b766585f9b4ffabeef2f36200c275976b93f2c7.tar.gz |
printf should return negative value on error
[BZ #11741]
Fixed bug where printf and family may return a spurious success when
printing padded formats.
Diffstat (limited to 'stdio-common/vfprintf.c')
-rw-r--r-- | stdio-common/vfprintf.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index 17d3f42a97..0c1339febd 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -87,8 +87,18 @@ # define PUT(F, S, N) _IO_sputn ((F), (S), (N)) # define PAD(Padchar) \ - if (width > 0) \ - done_add (_IO_padn (s, (Padchar), width)) + do { \ + if (width > 0) \ + { \ + unsigned int d = _IO_padn (s, (Padchar), width); \ + if (__builtin_expect (d == EOF, 0)) \ + { \ + done = -1; \ + goto all_done; \ + } \ + done_add (d); \ + } \ + } while (0) # define PUTC(C, F) _IO_putc_unlocked (C, F) # define ORIENT if (_IO_vtable_offset (s) == 0 && _IO_fwide (s, -1) != -1)\ return -1 @@ -106,8 +116,18 @@ # define PUT(F, S, N) _IO_sputn ((F), (S), (N)) # define PAD(Padchar) \ - if (width > 0) \ - done_add (_IO_wpadn (s, (Padchar), width)) + do { \ + if (width > 0) \ + { \ + unsigned int d = _IO_wpadn (s, (Padchar), width); \ + if (__builtin_expect (d == EOF, 0)) \ + { \ + done = -1; \ + goto all_done; \ + } \ + done_add (d); \ + } \ + } while (0) # define PUTC(C, F) _IO_putwc_unlocked (C, F) # define ORIENT if (_IO_fwide (s, 1) != 1) return -1 |