This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Hi! %[...] conversion did not return EOF when end-of-file condition is detected before any matches. This patch tries to fix it. Both tst-sscanf and tstscanf pass with this in, but I'd appreciate if you had a look at it once more so that nothing can be broken. The LONG/non-wide case was not converted to while (--width > 0 && inchar () != EOF) because I changed the goto again into continue and it should not do anything with width, I don't know if a comment is needed or if it is obvious. 2000-10-04 Jakub Jelinek <jakub@redhat.com> * stdio-common/vfscanf.c (_IO_vfscanf): For [ conversion do input_error() if EOF is seen before processing. * stdio-common/tstscanf.c (main): Add testcase. --- libc/stdio-common/vfscanf.c.jj Tue Sep 26 09:23:09 2000 +++ libc/stdio-common/vfscanf.c Wed Oct 4 14:46:58 2000 @@ -1973,13 +1973,13 @@ __vfscanf (FILE *s, const char *format, { size_t now = read_in; #ifdef COMPILE_WSCANF + if (inchar () == WEOF) + input_error (); + do { wchar_t *runp; - if (inchar () == WEOF) - break; - /* Test whether it's in the scanlist. */ runp = tw; while (runp < wp) @@ -2063,21 +2063,20 @@ __vfscanf (FILE *s, const char *format, } } } - while (--width > 0); + while (--width > 0 && inchar () != WEOF); out: #else char buf[MB_LEN_MAX]; size_t cnt = 0; mbstate_t cstate; + if (inchar () == EOF) + input_error (); + memset (&cstate, '\0', sizeof (cstate)); do { - again: - if (inchar () == EOF) - break; - if (wp[c] == not_in) { ungetc_not_eof (c, s); @@ -2097,7 +2096,7 @@ __vfscanf (FILE *s, const char *format, /* Possibly correct character, just not enough input. */ assert (cnt < MB_CUR_MAX); - goto again; + continue; } if (n != cnt) @@ -2142,8 +2141,11 @@ __vfscanf (FILE *s, const char *format, } } } + + if (--width <= 0) + break; } - while (--width > 0); + while (inchar () != EOF); if (cnt != 0) /* We stopped in the middle of recognizing another @@ -2175,6 +2177,10 @@ __vfscanf (FILE *s, const char *format, else { size_t now = read_in; + + if (inchar () == EOF) + input_error (); + #ifdef COMPILE_WSCANF memset (&state, '\0', sizeof (state)); @@ -2184,9 +2190,6 @@ __vfscanf (FILE *s, const char *format, wchar_t *runp; size_t n; - if (inchar () == WEOF) - break; - /* Test whether it's in the scanlist. */ runp = tw; while (runp < wp) @@ -2275,14 +2278,11 @@ __vfscanf (FILE *s, const char *format, assert (n <= MB_CUR_MAX); str += n; } - while (--width > 0); + while (--width > 0 && inchar () != WEOF); out2: #else do { - if (inchar () == EOF) - break; - if (wp[c] == not_in) { ungetc_not_eof (c, s); @@ -2328,7 +2328,7 @@ __vfscanf (FILE *s, const char *format, } } } - while (--width > 0); + while (--width > 0 && inchar () != EOF); #endif if (now == read_in) --- libc/stdio-common/tstscanf.c.jj Thu Jul 27 15:59:44 2000 +++ libc/stdio-common/tstscanf.c Wed Oct 4 14:51:03 2000 @@ -46,6 +46,12 @@ main (int argc, char **argv) result = 1; } + if (sscanf ("", "%10[a-z]", buf) != EOF) + { + fputs ("test failed!\n", stdout); + result = 1; + } + sscanf ("conversion] Zero flag Ze]ro#\n", "%*[^]] %[^#]\n", buf); if (strcmp (buf, "] Zero flag Ze]ro") != 0) { Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |