shithub: riscv

Download patch

ref: 78aec6d5c67cab79e03cdbe4f1a1bd7a7aa15612
parent: ed4645979c0a6286d92c6bddaee7ea71727b0afb
author: Ori Bernstein <ori@eigenstate.org>
date: Fri May 15 12:46:20 EDT 2020

Fix scans of more than one character in %[]

This got broken in d8e877a89dae, where we returned 0 on the
first mismatch; we want to return 0 only when we consumed no
characters.

--- a/sys/src/ape/lib/ap/stdio/vfscanf.c
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c
@@ -416,7 +416,7 @@
 		}
 		if(!match(c, pat)){
 			nungetc(c, f);
-			return 0;
+			goto Done;
 		}
 		if(store)
 			*s++=c;
@@ -424,5 +424,5 @@
 	}
 Done:
 	if(store) *s='\0';
-	return 1;
+	return nn > 0;
 }
--- a/sys/src/libstdio/vfscanf.c
+++ b/sys/src/libstdio/vfscanf.c
@@ -339,6 +339,7 @@
 	int c, nn;
 	register char *s;
 	register const char *pat;
+
 	pat=++fmtp;
 	if(*fmtp=='^') fmtp++;
 	if(*fmtp!='\0') fmtp++;
@@ -354,7 +355,7 @@
 		}
 		if(!match(c, pat)){
 			nungetc(c, f);
-			return 0;
+			goto Done;
 		}
 		if(store) *s++=c;
 		nn++;
@@ -361,5 +362,5 @@
 	}
 Done:
 	if(store) *s='\0';
-	return 1;
+	return nn > 0;
 }