fix '%[]' specifiers and '%n' (thanks phil9)
When a match() fails, we need to unget the character we tried to match against, rather than leaving it consumed. Also, we can't break out of a conversion before we reach the end of a format string, because things like the '%n' conversion do not consume anything, and should still be handled.
This commit is contained in:
parent
758edf2b14
commit
bfc8cdfff5
|
@ -72,7 +72,6 @@ int vfscanf(FILE *f, const char *s, va_list args)
|
||||||
do
|
do
|
||||||
c=ngetc(f);
|
c=ngetc(f);
|
||||||
while(isspace(c));
|
while(isspace(c));
|
||||||
if(c==EOF) return ncvt?ncvt:EOF;
|
|
||||||
nungetc(c, f);
|
nungetc(c, f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -396,13 +395,14 @@ icvt_sq(FILE *f, va_list *args, int store, int width, int)
|
||||||
if(nn==0) return 0;
|
if(nn==0) return 0;
|
||||||
else goto Done;
|
else goto Done;
|
||||||
}
|
}
|
||||||
if(!match(c, pat))
|
if(!match(c, pat)){
|
||||||
break;
|
nungetc(c, f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if(store)
|
if(store)
|
||||||
*s++=c;
|
*s++=c;
|
||||||
nn++;
|
nn++;
|
||||||
}
|
}
|
||||||
nungetc(c, f);
|
|
||||||
Done:
|
Done:
|
||||||
if(store) *s='\0';
|
if(store) *s='\0';
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -68,7 +68,6 @@ int vfscanf(FILE *f, const char *s, va_list args){
|
||||||
do
|
do
|
||||||
c=ngetc(f);
|
c=ngetc(f);
|
||||||
while(isspace(c));
|
while(isspace(c));
|
||||||
if(c==EOF) return ncvt?ncvt:EOF;
|
|
||||||
nungetc(c, f);
|
nungetc(c, f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -353,11 +352,13 @@ static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
|
||||||
if(nn==0) return 0;
|
if(nn==0) return 0;
|
||||||
else goto Done;
|
else goto Done;
|
||||||
}
|
}
|
||||||
if(!match(c, pat)) break;
|
if(!match(c, pat)){
|
||||||
|
nungetc(c, f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if(store) *s++=c;
|
if(store) *s++=c;
|
||||||
nn++;
|
nn++;
|
||||||
}
|
}
|
||||||
nungetc(c, f);
|
|
||||||
Done:
|
Done:
|
||||||
if(store) *s='\0';
|
if(store) *s='\0';
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue