summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-09-22 16:03:46 +0000
committerUlrich Drepper <drepper@redhat.com>1999-09-22 16:03:46 +0000
commit9df541684a60a94d94cc0c08de119eec718f2318 (patch)
tree2867818d5fcba8d0cbf7547e319f0646534798b1 /stdio-common
parent5b5255f197c7b6355010d781370a3331ab5b68c3 (diff)
downloadglibc-9df541684a60a94d94cc0c08de119eec718f2318.tar.gz
glibc-9df541684a60a94d94cc0c08de119eec718f2318.tar.xz
glibc-9df541684a60a94d94cc0c08de119eec718f2318.zip
Update.
1999-09-22  Andreas Jaeger  <aj@suse.de>

	* stdio-common/tstscanf.c (main): Add test case from PR libc/1313
	reported by Ben Caradoc-Davies <bmcd@physics.otago.ac.nz>.
		
1999-09-22  Andreas Schwab  <schwab@suse.de>

	* stdio-common/vfscanf.c: Fix width handling when scanning floats.

1999-04-02  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* elf/Makefile (CFLAGS-multiload.c): Change to allow building in
	the source directory.  Fixes PR libc/1059.
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/tstscanf.c14
-rw-r--r--stdio-common/vfscanf.c50
2 files changed, 52 insertions, 12 deletions
diff --git a/stdio-common/tstscanf.c b/stdio-common/tstscanf.c
index 4e56251e03..93f77ce2d9 100644
--- a/stdio-common/tstscanf.c
+++ b/stdio-common/tstscanf.c
@@ -265,5 +265,19 @@ main (int argc, char **argv)
       }
   }
 
+  fputs ("Test 9:\n", stdout);
+  {
+    /* From PR libc/1313 reported by Ben Caradoc-Davies <bmcd@physics.otago.ac.nz>.  */
+    float value;
+    int res;
+    
+    res = sscanf ("0123", "%2f", &value);
+    if (res != 1 || value != 1.0)
+      {
+	fputs ("test failed!\n", stdout);
+	result = 1;
+      }
+  }
+  
   exit (result);
 }
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index a6e3bb2a23..b50e7b8323 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -1300,7 +1300,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 	  if (c == L_('-') || c == L_('+'))
 	    {
 	      negative = c == L_('-');
-	      if (inchar () == EOF)
+	      if (width == 0 || inchar () == EOF)
 		/* EOF is only an input error before we read any chars.  */
 		conv_error ();
 	      if (! ISDIGIT (c) && c != decimal)
@@ -1320,11 +1320,15 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 	    {
 	      /* Maybe "nan".  */
 	      ADDW (c);
-	      if (inchar () == EOF || TOLOWER (c) != L_('a'))
+	      if (width == 0 || inchar () == EOF || TOLOWER (c) != L_('a'))
 		input_error ();
+	      if (width > 0)
+		--width;
 	      ADDW (c);
-	      if (inchar () == EOF || TOLOWER (c) != L_('n'))
+	      if (width == 0 || inchar () == EOF || TOLOWER (c) != L_('n'))
 		input_error ();
+	      if (width > 0)
+		--width;
 	      ADDW (c);
 	      /* It is "nan".  */
 	      goto scan_float;
@@ -1333,30 +1337,48 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 	    {
 	      /* Maybe "inf" or "infinity".  */
 	      ADDW (c);
-	      if (inchar () == EOF || TOLOWER (c) != L_('n'))
+	      if (width == 0 || inchar () == EOF || TOLOWER (c) != L_('n'))
 		input_error ();
+	      if (width > 0)
+		--width;
 	      ADDW (c);
-	      if (inchar () == EOF || TOLOWER (c) != L_('f'))
+	      if (width == 0 || inchar () == EOF || TOLOWER (c) != L_('f'))
 		input_error ();
+	      if (width > 0)
+		--width;
 	      ADDW (c);
 	      /* It is as least "inf".  */
-	      if (inchar () != EOF)
+	      if (width != 0 && inchar () != EOF)
 		{
 		  if (TOLOWER (c) == L_('i'))
 		    {
+		      if (width > 0)
+			--width;
 		      /* Now we have to read the rest as well.  */
 		      ADDW (c);
-		      if (inchar () == EOF || TOLOWER (c) != L_('n'))
+		      if (width == 0 || inchar () == EOF
+			  || TOLOWER (c) != L_('n'))
 			input_error ();
+		      if (width > 0)
+			--width;
 		      ADDW (c);
-		      if (inchar () == EOF || TOLOWER (c) != L_('i'))
+		      if (width == 0 || inchar () == EOF
+			  || TOLOWER (c) != L_('i'))
 			input_error ();
+		      if (width > 0)
+			--width;
 		      ADDW (c);
-		      if (inchar () == EOF || TOLOWER (c) != L_('t'))
+		      if (width == 0 || inchar () == EOF
+			  || TOLOWER (c) != L_('t'))
 			input_error ();
+		      if (width > 0)
+			--width;
 		      ADDW (c);
-		      if (inchar () == EOF || TOLOWER (c) != L_('y'))
+		      if (width == 0 || inchar () == EOF
+			  || TOLOWER (c) != L_('y'))
 			input_error ();
+		      if (width > 0)
+			--width;
 		      ADDW (c);
 		    }
 		  else
@@ -1368,11 +1390,13 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 
 	  is_hexa = 0;
 	  exp_char = L_('e');
-	  if (c == L_('0'))
+	  if (width != 0 && c == L_('0'))
 	    {
 	      ADDW (c);
 	      c = inchar ();
-	      if (TOLOWER (c) == L_('x'))
+	      if (width > 0)
+		--width;
+	      if (width != 0 && TOLOWER (c) == L_('x'))
 		{
 		  /* It is a number in hexadecimal format.  */
 		  ADDW (c);
@@ -1383,6 +1407,8 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 		  /* Grouping is not allowed.  */
 		  flags &= ~GROUP;
 		  c = inchar ();
+		  if (width > 0)
+		    --width;
 		}
 	    }