diff options
Diffstat (limited to 'stdio-common/vfscanf.c')
-rw-r--r-- | stdio-common/vfscanf.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index 256f3eab33..cba6847266 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -54,8 +54,10 @@ # undef va_list # define va_list _IO_va_list -# define ungetc(c, s) (--read_in, _IO_ungetc (c, s)) -# define inchar() ((c = _IO_getc_unlocked (s)), (void) ++read_in, c) +# define ungetc(c, s) ((void) ((int) c != EOF && --read_in), \ + _IO_ungetc (c, s)) +# define inchar() ((c = _IO_getc_unlocked (s)), \ + (void) (c != EOF && ++read_in), c) # define encode_error() do { \ if (errp != NULL) *errp |= 4; \ _IO_funlockfile (s); \ @@ -98,8 +100,8 @@ _IO_flockfile (S) # define UNLOCK_STREAM __libc_cleanup_region_end (1) #else -# define ungetc(c, s) (--read_in, ungetc (c, s)) -# define inchar() ((c = getc (s)), (void) ++read_in, c) +# define ungetc(c, s) ((void) (c != EOF && --read_in), ungetc (c, s)) +# define inchar() ((c = getc (s)), (void) (c != EOF && ++read_in), c) # define encode_error() do { \ funlockfile (s); \ __set_errno (EILSEQ); \ @@ -717,9 +719,6 @@ __vfscanf (FILE *s, const char *format, va_list argptr) STRING_ADD_CHAR (str, c, char); } while ((width <= 0 || --width > 0) && inchar () != EOF); - if (c == EOF) - --read_in; - if (!(flags & SUPPRESS)) { *str = '\0'; @@ -943,14 +942,16 @@ __vfscanf (FILE *s, const char *format, va_list argptr) else if ((flags & GROUP) && c == thousands && !got_dot) ADDW (c); else - break; + { + /* The last read character is not part of the number + anymore. */ + ungetc (c, s); + break; + } if (width > 0) --width; } - while (inchar () != EOF && width != 0); - - /* The last read character is not part of the number anymore. */ - ungetc (c, s); + while (width != 0 && inchar () != EOF); if (wpsize == 0) conv_error (); |