diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-07-08 10:08:25 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2007-07-08 10:08:25 +0000 |
commit | 41dfb5c63862857dadc816caea4bcb4fb268cdf1 (patch) | |
tree | c8ac7b012db7424009fe2956ab62141c633b26e6 | |
parent | Update Copyright lines. (diff) | |
download | glibc-41dfb5c63862857dadc816caea4bcb4fb268cdf1.tar.gz glibc-41dfb5c63862857dadc816caea4bcb4fb268cdf1.tar.bz2 glibc-41dfb5c63862857dadc816caea4bcb4fb268cdf1.zip |
[BZ #4745]
* stdio-common/vfscanf.c (_IO_vfscanf): Add additional test for EOF
in loop to look for conversion specifier to avoid testing of
wrong errno value.
* stdio-common/Makefile (tests): Add bug18, bug18a, bug19, bug19a.
* stdio-common/bug18.c: New file.
* stdio-common/bug18a.c: New file.
* stdio-common/bug19.c: New file.
* stdio-common/bug19a.c: New file.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | stdio-common/Makefile | 3 | ||||
-rw-r--r-- | stdio-common/bug18.c | 48 | ||||
-rw-r--r-- | stdio-common/bug18a.c | 6 | ||||
-rw-r--r-- | stdio-common/bug19.c | 58 | ||||
-rw-r--r-- | stdio-common/bug19a.c | 7 | ||||
-rw-r--r-- | stdio-common/vfscanf.c | 11 |
7 files changed, 141 insertions, 4 deletions
@@ -1,3 +1,15 @@ +2007-07-07 Ulrich Drepper <drepper@redhat.com> + + [BZ #4745] + * stdio-common/vfscanf.c (_IO_vfscanf): Add additional test for EOF + in loop to look for conversion specifier to avoid testing of + wrong errno value. + * stdio-common/Makefile (tests): Add bug18, bug18a, bug19, bug19a. + * stdio-common/bug18.c: New file. + * stdio-common/bug18a.c: New file. + * stdio-common/bug19.c: New file. + * stdio-common/bug19a.c: New file. + 2007-06-06 Jakub Jelinek <jakub@redhat.com> [BZ #4586] diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 735b40104a..4ead0f9574 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -54,7 +54,8 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \ tst-swprintf tst-fseek tst-fmemopen test-vfprintf tst-gets \ tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 bug15 \ tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \ - tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 + tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \ + bug19 bug19a test-srcs = tst-unbputc tst-printf diff --git a/stdio-common/bug18.c b/stdio-common/bug18.c new file mode 100644 index 0000000000..2e4c378c13 --- /dev/null +++ b/stdio-common/bug18.c @@ -0,0 +1,48 @@ +#include <assert.h> +#include <errno.h> +#include <stdio.h> + +#ifndef CHAR +# define CHAR char +# define L(str) str +# define SSCANF sscanf +#endif + + +static int +do_test (void) +{ + printf("setting errno to EINTR\n"); + errno = EINTR; + + printf("checking sscanf\n"); + + CHAR str[] = L("7-11"); + int i, j, n; + + i = j = n = 0; + SSCANF (str, L(" %i - %i %n"), &i, &j, &n); + printf ("found %i-%i (length=%i)\n", i, j, n); + + int result = 0; + if (i != 7) + { + printf ("i is %d, expected 7\n", i); + result = 1; + } + if (j != 11) + { + printf ("j is %d, expected 11\n", j); + result = 1; + } + if (n != 4) + { + printf ("n is %d, expected 4\n", j); + result = 1; + } + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/bug18a.c b/stdio-common/bug18a.c new file mode 100644 index 0000000000..663cbf4fb7 --- /dev/null +++ b/stdio-common/bug18a.c @@ -0,0 +1,6 @@ +#include <wchar.h> +#define CHAR wchar_t +#define L(str) L##str +#define SSCANF swscanf + +#include "bug18.c" diff --git a/stdio-common/bug19.c b/stdio-common/bug19.c new file mode 100644 index 0000000000..e083304bda --- /dev/null +++ b/stdio-common/bug19.c @@ -0,0 +1,58 @@ +#include <assert.h> +#include <errno.h> +#include <stdio.h> + +#ifndef CHAR +# define CHAR char +# define L(str) str +# define FPUTS fputs +# define FSCANF fscanf +#endif + + +static int +do_test (void) +{ + FILE *fp = tmpfile (); + if (fp == NULL) + { + puts ("cannot open file"); + return 1; + } + + FPUTS (L("7-11"), fp); + rewind (fp); + + printf("setting errno to EINTR\n"); + errno = EINTR; + + printf("checking sscanf\n"); + + int i, j, n; + + i = j = n = 0; + FSCANF (fp, L(" %i - %i %n"), &i, &j, &n); + printf ("found %i-%i (length=%i)\n", i, j, n); + + int result = 0; + if (i != 7) + { + printf ("i is %d, expected 7\n", i); + result = 1; + } + if (j != 11) + { + printf ("j is %d, expected 11\n", j); + result = 1; + } + if (n != 4) + { + printf ("n is %d, expected 4\n", j); + result = 1; + } + + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/stdio-common/bug19a.c b/stdio-common/bug19a.c new file mode 100644 index 0000000000..c723398503 --- /dev/null +++ b/stdio-common/bug19a.c @@ -0,0 +1,7 @@ +#include <wchar.h> +#define CHAR wchar_t +#define L(str) L##str +#define FPUTS fputws +#define FSCANF fwscanf + +#include "bug19.c" diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index b1469b9a9e..9e6daced5d 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -530,12 +530,17 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr, { /* Eat whitespace. */ int save_errno = errno; - errno = 0; + __set_errno (0); do - if (__builtin_expect (inchar () == EOF && errno == EINTR, 0)) + /* We add the additional test for EOF here since otherwise + inchar will restore the old errno value which might be + EINTR but does not indicate an interrupt since nothing + was read at this time. */ + if (__builtin_expect ((c == EOF || inchar () == EOF) + && errno == EINTR, 0)) input_error (); while (ISSPACE (c)); - errno = save_errno; + __set_errno (save_errno); ungetc (c, s); skip_space = 0; } |