summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-05-15 16:46:20 -0700
committerOri Bernstein <ori@eigenstate.org>2020-05-15 16:46:20 -0700
commit78aec6d5c67cab79e03cdbe4f1a1bd7a7aa15612 (patch)
tree555810535e5c50097cc4ed219b14819e09cc4207 /sys
parented4645979c0a6286d92c6bddaee7ea71727b0afb (diff)
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/src/ape/lib/ap/stdio/vfscanf.c4
-rw-r--r--sys/src/libstdio/vfscanf.c5
2 files changed, 5 insertions, 4 deletions
diff --git a/sys/src/ape/lib/ap/stdio/vfscanf.c b/sys/src/ape/lib/ap/stdio/vfscanf.c
index 5cbc1fee5..ac09b86ea 100644
--- a/sys/src/ape/lib/ap/stdio/vfscanf.c
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c
@@ -416,7 +416,7 @@ icvt_sq(FILE *f, va_list *args, int store, int width, int)
}
if(!match(c, pat)){
nungetc(c, f);
- return 0;
+ goto Done;
}
if(store)
*s++=c;
@@ -424,5 +424,5 @@ icvt_sq(FILE *f, va_list *args, int store, int width, int)
}
Done:
if(store) *s='\0';
- return 1;
+ return nn > 0;
}
diff --git a/sys/src/libstdio/vfscanf.c b/sys/src/libstdio/vfscanf.c
index d811b7803..be5c71284 100644
--- a/sys/src/libstdio/vfscanf.c
+++ b/sys/src/libstdio/vfscanf.c
@@ -339,6 +339,7 @@ static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
int c, nn;
register char *s;
register const char *pat;
+
pat=++fmtp;
if(*fmtp=='^') fmtp++;
if(*fmtp!='\0') fmtp++;
@@ -354,12 +355,12 @@ static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
}
if(!match(c, pat)){
nungetc(c, f);
- return 0;
+ goto Done;
}
if(store) *s++=c;
nn++;
}
Done:
if(store) *s='\0';
- return 1;
+ return nn > 0;
}