about summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/Makefile2
-rw-r--r--stdio-common/scanf10.c15
-rw-r--r--stdio-common/vfscanf.c8
3 files changed, 23 insertions, 2 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 5189dd7eef..f4e49e6b9d 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -43,7 +43,7 @@ tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \
 	 xbug errnobug \
 	 bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 \
 	 tfformat tiformat tstdiomisc \
-	 scanf1 scanf2 scanf3 scanf4 scanf5 scanf7 scanf8 scanf9
+	 scanf1 scanf2 scanf3 scanf4 scanf5 scanf7 scanf8 scanf9 scanf10
 
 
 include ../Rules
diff --git a/stdio-common/scanf10.c b/stdio-common/scanf10.c
new file mode 100644
index 0000000000..f8961378ef
--- /dev/null
+++ b/stdio-common/scanf10.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+  const char teststring[] = "<tag `word'>";
+  int retc, a, b;
+
+  retc = sscanf (teststring, "<%*s `%n%*s%n'>", &a, &b);
+
+  printf ("retc=%d a=%d b=%d\n", retc, a, b);
+
+  return retc == -1 && a == 6 && b == 12 ? 0 : 1;
+}
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index 7a3440c99a..cb6d39629e 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -524,7 +524,10 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 		  if (First)						      \
 		    input_error ();					      \
 		  else							      \
-		    break;						      \
+		    {							      \
+		      --read_in;					      \
+		      break;						      \
+		    }							      \
 		val = c;						      \
 		if (val >= 0x80)					      \
 		  {							      \
@@ -667,6 +670,9 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
 	      STRING_ADD_CHAR (str, c, char);
 	    } while ((width <= 0 || --width > 0) && inchar () != EOF);
 
+	  if (c == EOF)
+	    --read_in;
+
 	  if (!(flags & SUPPRESS))
 	    {
 	      *str = '\0';