The scanf functions must return EOF if source starts at the end of input.

The $fscanf() and $sscanf() functions are defined to return EOF when
the end of input is reached before any matches or match failures have
occurred.
(cherry picked from commit c5ee1fdbf5)
This commit is contained in:
Cary R 2009-07-23 14:34:54 -07:00 committed by Stephen Williams
parent d0a12f5b14
commit 7acafd128f
1 changed files with 8 additions and 0 deletions

View File

@ -240,6 +240,14 @@ static int scan_format(vpiHandle callh, struct byte_source*src, vpiHandle argv)
vpi_get_value(item, &val);
fmtp = fmt = strdup(val.value.str);
/* See if we are at EOF before we even start. */
ch = byte_getc(src);
if (ch == EOF) {
rc = EOF;
match_fail = 1;
}
byte_ungetc(src, ch);
while ( fmtp && *fmtp != 0 && !match_fail) {
if (isspace(*fmtp)) {