diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index d797179eaee..e5d5244d32d 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -90,6 +90,8 @@ int _FUNCTION_ { #endif /* CONSOLE */ #endif /* WIDE_SCANF */ nch = _GETC_(file); + if (nch == _EOF_) return _EOF_; + va_start(ap, format); while (*format) { /* a whitespace character in the format string causes scanf to read, diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 7de595db66e..fba2c04fcf7 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -26,8 +26,14 @@ static void test_sscanf( void ) { char buffer[100]; char format[20]; - int result; + int result, ret; + /* check EOF */ + strcpy(buffer,""); + ret = sscanf(buffer, "%d", &result); + ok( ret == EOF,"sscanf returns %x instead of %x", ret, EOF ); + + /* check %x */ strcpy(buffer,"0x519"); ok( sscanf(buffer, "%x", &result) == 1, "sscanf failed" ); ok( result == 0x519,"sscanf reads %x instead of %x", result, 0x519 );