From c5ee1fdbf55d3a371950e45ed78a20a1013a877b Mon Sep 17 00:00:00 2001 From: Cary R Date: Thu, 23 Jul 2009 14:34:54 -0700 Subject: [PATCH] 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. --- vpi/sys_scanf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vpi/sys_scanf.c b/vpi/sys_scanf.c index f500aa585..b523d2d60 100644 --- a/vpi/sys_scanf.c +++ b/vpi/sys_scanf.c @@ -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)) {