diff options
Diffstat (limited to 'stdio-common')
-rw-r--r-- | stdio-common/Makefile | 2 | ||||
-rw-r--r-- | stdio-common/printf_fp.c | 4 | ||||
-rw-r--r-- | stdio-common/tst-ungetc.c | 42 | ||||
-rw-r--r-- | stdio-common/tstscanf.c | 9 |
4 files changed, 54 insertions, 3 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile index d4a167580c..2970dd3db0 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -37,7 +37,7 @@ aux := errlist siglist distribute := _itoa.h printf-parse.h tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \ - temptest tst-fileno test-fwrite \ + temptest tst-fileno test-fwrite tst-ungetc \ xbug errnobug \ bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 \ tfformat tiformat tstdiomisc \ diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index 7b46cd6bb9..e0fb742cfe 100644 --- a/stdio-common/printf_fp.c +++ b/stdio-common/printf_fp.c @@ -208,7 +208,9 @@ __printf_fp (FILE *fp, tmp[fracsize - scalesize] = hi; hi = tmp[0]; - fracsize = __mpn_normal_size (frac, scalesize); + fracsize = scalesize; + while (fracsize != 0 && frac[fracsize - 1] == 0) + --fracsize; if (fracsize == 0) { /* We're not prepared for an mpn variable with zero diff --git a/stdio-common/tst-ungetc.c b/stdio-common/tst-ungetc.c new file mode 100644 index 0000000000..67c45d4028 --- /dev/null +++ b/stdio-common/tst-ungetc.c @@ -0,0 +1,42 @@ +/* Test for ungetc bugs. */ + +#include <stdio.h> + +#define assert(x) \ + if (!(x)) \ + { \ + fputs ("test failed: " #x "\n", stderr); \ + retval = 1; \ + goto the_end; \ + } + +int +main (int argc, char *argv[]) +{ + char *name; + FILE *fp = NULL; + int retval = 0; + int c; + + name = tmpnam (NULL); + fp = fopen (name, "w"); + assert (fp != NULL) + fputs ("bl", fp); + fclose (fp); + fp = NULL; + + fp = fopen (name, "r"); + assert (fp != NULL) + assert (getc (fp) != EOF); + assert ((c = getc (fp)) != EOF); + assert (getc (fp) == EOF); + assert (ungetc (c, fp) == c); + assert (feof (fp) == 0); + +the_end: + if (fp != NULL) + fclose (fp); + unlink (name); + + return retval; +} diff --git a/stdio-common/tstscanf.c b/stdio-common/tstscanf.c index 738b25a65e..005dc2dfce 100644 --- a/stdio-common/tstscanf.c +++ b/stdio-common/tstscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -36,6 +36,13 @@ DEFUN(main, (argc, argv), int argc AND char **argv) if (sscanf ("0", "%d", &x) != 1) exit (EXIT_FAILURE); + sscanf ("conversion] Zero flag Ze]ro#\n", "%*[^]] %[^#]\n", buf); + if (strcmp (buf, "] Zero flag Ze]ro") != 0) + { + fputs ("test failed!", stderr); + return 1; + } + if (argc == 2 && !strcmp (argv[1], "-opipe")) { out = popen ("/bin/cat", "w"); |