]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* stdio-common/vfscanf.c: Fix problems in width accounting.
authorUlrich Drepper <drepper@redhat.com>
Sun, 18 Feb 2007 19:03:30 +0000 (19:03 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sun, 18 Feb 2007 19:03:30 +0000 (19:03 +0000)
* stdio-common/tst-sscanf.c (double_tests): New tests.
(main): Hook them up.

ChangeLog
stdio-common/tst-sscanf.c
stdio-common/vfscanf.c

index fc077832aaf26aa8a327ebe4544e0b8de59c46c0..d898823f51da0b50ea335aedd0b65c49aab3abf7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2007-02-18  Ulrich Drepper  <drepper@redhat.com>
 
+       * stdio-common/vfscanf.c: Fix problems in width accounting.
+       * stdio-common/tst-sscanf.c (double_tests): New tests.
+       (main): Hook them up.
+
        * stdio-common/vfscanf.c: Remove unused WIDTH handling.
        More simplifications of floating-point reader.
 
index b76f757c90f4fdd68d777fd71ccf7397b170f7f8..a987e8779778098f7044c94da15db0801e51fc6f 100644 (file)
@@ -65,7 +65,7 @@ const long int val_long[] =
   -12345678, 987654321, 123456789, 987654321, 123456789, 987654321
 };
 
-struct int_test
+struct test
 {
   const CHAR *str;
   const CHAR *fmt;
@@ -99,6 +99,17 @@ struct int_test
   { L("foo \t %bar1"), L("foo%%bar%d"), 1 }
 };
 
+struct test double_tests[] =
+{
+  { L("-1"), L("%1g"), 0 },
+  { L("-.1"), L("%2g"), 0 },
+  { L("-inf"), L("%3g"), 0 },
+  { L("+0"), L("%1g"),  },
+  { L("-0x1p0"), L("%2g"), 1 },
+  { L("-..1"), L("%g"), 0 },
+  { L("-inf"), L("%g"), 1 }
+};
+
 int
 main (void)
 {
@@ -172,5 +183,19 @@ main (void)
        }
     }
 
+  for (i = 0; i < sizeof (double_tests) / sizeof (double_tests[0]); ++i)
+    {
+      double dummy;
+      int ret;
+
+      if ((ret = SSCANF (double_tests[i].str, double_tests[i].fmt,
+                        &dummy)) != double_tests[i].retval)
+       {
+         printf ("double_tests[%d] returned %d != %d\n",
+                 i, ret, double_tests[i].retval);
+         result = 1;
+       }
+    }
+
   return result;
 }
index 1149686d75ad8b1e6f1aed23c07005180169b035..90e7e36a5f07d017fa880d9d3dfd07da87f8fe70 100644 (file)
@@ -1585,6 +1585,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
        case L_('a'):
        case L_('A'):
          c = inchar ();
+         if (width > 0)
+           --width;
          if (__builtin_expect (c == EOF, 0))
            input_error ();
 
@@ -1712,7 +1714,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
                }
            }
 
-         do
+         while (1)
            {
              if (ISDIGIT (c))
                ADDW (c);
@@ -1818,10 +1820,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
                    }
 #endif
                }
+
+             if (width == 0 || inchar () == EOF)
+               break;
+
              if (width > 0)
                --width;
            }
-         while (width != 0 && inchar () != EOF);
 
          /* Have we read any character?  If we try to read a number
             in hexadecimal notation and we have read only the `0x'