From 87cdc43e114ca31c91348622bf71aeeaa6c2ee75 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 15 Dec 1995 03:29:46 +0000 Subject: [PATCH] Fri Dec 15 01:31:56 1995 Ulrich Drepper * stdio-common/Makefile (tests): Add bug8 and bug9. * stdio-common/bug8.c, stdio-common/bug9.c: New tests. * stdio-common/vfscanf.c: Fix bug in dynamic buffer handling. * stdlib/strtod.c: Correct spelling: nominator -> numerator. Thanks to Jim Meyering. Sat Nov 25 06:05:12 1995 H.J. Lu * stdio-common/vfscanf.c: Always check width !=0. Correctly handle %%. --- stdio-common/Makefile | 2 +- stdio-common/bug8.c | 26 ++++++++++++++++++++++++++ stdio-common/bug9.c | 22 ++++++++++++++++++++++ stdio-common/vfscanf.c | 25 +++++++++++++++---------- stdlib/strtod.c | 4 ++-- 5 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 stdio-common/bug8.c create mode 100644 stdio-common/bug9.c diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 8ae8b48e1d..d2cb97517e 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -39,7 +39,7 @@ distribute := _itoa.h printf-parse.h tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \ temptest tst-fileno test-fwrite \ xbug errnobug \ - bug1 bug2 bug3 bug4 bug5 bug6 bug7 \ + bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 \ tfformat tiformat tstdiomisc diff --git a/stdio-common/bug8.c b/stdio-common/bug8.c new file mode 100644 index 0000000000..39a41855de --- /dev/null +++ b/stdio-common/bug8.c @@ -0,0 +1,26 @@ +#include +#include + +main() +{ + char buf[100]; + int point, x, y; + int status = 0; + + sscanf("0x10 10", "%x %x", &x, &y); + sprintf(buf, "%d %d", x, y); + puts (buf); + status |= strcmp (buf, "16 16"); + sscanf("P012349876", "P%1d%4d%4d", &point, &x, &y); + sprintf(buf, "%d %d %d", point, x, y); + status |= strcmp (buf, "0 1234 9876"); + puts (buf); + sscanf("P112349876", "P%1d%4d%4d", &point, &x, &y); + sprintf(buf, "%d %d %d", point, x, y); + status |= strcmp (buf, "1 1234 9876"); + puts (buf); + + puts (status ? "Test failed" : "Test passed"); + + return status; +} diff --git a/stdio-common/bug9.c b/stdio-common/bug9.c new file mode 100644 index 0000000000..5a7166ce90 --- /dev/null +++ b/stdio-common/bug9.c @@ -0,0 +1,22 @@ +#include +#include + +int +main() +{ + char buf[100]; + int a, b; + int status = 0; + + sscanf ("12ab", "%dab%n", &a, &b); + sprintf (buf, "%d, %d", a, b); + puts (buf); + status |= strcmp (buf, "12, 4"); + + sscanf ("12ab100", "%dab%n100", &a, &b); + sprintf (buf, "%d, %d", a, b); + puts (buf); + status |= strcmp (buf, "12, 4"); + + return status; +} diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index 76c9936abe..9a5ac8241a 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -50,9 +50,9 @@ Cambridge, MA 02139, USA. */ # define va_list _IO_va_list # define ungetc(c, s) _IO_ungetc (c, s) -# define inchar() ((c = _IO_getc(s)), ++read_in, c) +# define inchar() ((c = _IO_getc (s)), ++read_in, c) # define conv_error() return ((errp != NULL && (*errp |= 2)), \ - (c == EOF || _IO_ungetc(c, s)), done) + (c == EOF || _IO_ungetc (c, s)), done) # define input_error() return ((errp != NULL && (*errp |= 1)), \ done == 0 ? EOF : done) @@ -69,8 +69,8 @@ Cambridge, MA 02139, USA. */ } \ } while (0) #else -# define inchar() ((c = getc(s)) == EOF ? EOF : (++read_in, c)) -# define conv_error() return (ungetc(c, s), done) +# define inchar() ((c = getc (s)), ++read_in, c) +# define conv_error() return (ungetc (c, s), done) # define input_error() return (done == 0 ? EOF : done) # define memory_error() return ((errno = ENOMEM), EOF) # define ARGCHECK(s, format) \ @@ -148,8 +148,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr) /* Workspace. */ char *tw; /* Temporary pointer. */ char *wp = NULL; /* Workspace. */ - size_t wpsize = 0; /* Currently used bytes in workspace. */ size_t wpmax = 0; /* Maximal size of workspace. */ + size_t wpsize; /* Currently used bytes in workspace. */ #define ADDW(Ch) \ do \ { \ @@ -158,7 +158,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) char *old = wp; \ wpmax = 200 > 2 * wpmax ? 200 : 2 * wpmax; \ wp = (char *) alloca (wpmax); \ - if (wpsize > 0) \ + if (old != NULL) \ memcpy (wp, old, wpsize); \ } \ wp[wpsize++] = (Ch); \ @@ -248,6 +248,9 @@ __vfscanf (FILE *s, const char *format, va_list argptr) group_flag = 0; is_short = is_long = is_long_double = malloc_string = 0; + /* Prepare temporary buffer. */ + wpsize = 0; + /* Check for a positional parameter specification. */ if (isdigit (*f)) { @@ -365,6 +368,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) case '%': /* Must match a literal '%'. */ if (c != fc) conv_error (); + inchar (); break; case 'n': /* Answer number of assignments done. */ @@ -513,7 +517,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) } /* Look for a leading indication of base. */ - if (c == '0') + if (width != 0 && c == '0') { if (width > 0) --width; @@ -521,7 +525,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) (void) inchar (); - if (tolower (c) == 'x') + if (width != 0 && tolower (c) == 'x') { if (base == 0) base = 16; @@ -540,7 +544,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) base = 10; /* Read the number into workspace. */ - do + while (c != EOF && width != 0) { if (base == 16 ? !isxdigit (c) : (!isdigit (c) || c - '0' >= base)) @@ -548,8 +552,9 @@ __vfscanf (FILE *s, const char *format, va_list argptr) ADDW (c); if (width > 0) --width; + + (void) inchar (); } - while (inchar () != EOF && width != 0); if (wpsize == 0 || (wpsize == 1 && (wp[0] == '+' || wp[0] == '-'))) diff --git a/stdlib/strtod.c b/stdlib/strtod.c index 8ce6e4d016..4104a98f0e 100644 --- a/stdlib/strtod.c +++ b/stdlib/strtod.c @@ -911,9 +911,9 @@ INTERNAL (STRTOF) (nptr, endptr, group) { if (num[0] >= d1) { - /* The nominator of the number occupies fewer bits than + /* The numerator of the number occupies fewer bits than the denominator but the one limb is bigger than the - high limb of the nominator. */ + high limb of the numerator. */ n1 = 0; n0 = num[0]; } -- 2.11.4.GIT