From: Piotr Caban Subject: [PATCH] msvcrt: Fix floating point numbers scanning when null-byte is preceding the number. Message-Id: Date: Mon, 13 Jan 2020 20:17:17 +0100 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48452 Signed-off-by: Piotr Caban --- dlls/msvcrt/scanf.h | 2 ++ dlls/msvcrt/tests/scanf.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index 1833c42dc3..ec3ec79995 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -393,6 +393,8 @@ _FUNCTION_ { /* skip initial whitespace */ while ((nch!=_EOF_) && _ISSPACE_(nch)) nch = _GETC_(file); + if (nch == _EOF_) + break; ctx.unget = nch; #ifdef STRING ctx.file = file; diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 95fd043e6f..57d9cc0ba1 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -165,6 +165,12 @@ static void test_sscanf( void ) ok(double_res >= 1.1e-30-1e-45 && double_res <= 1.1e-30+1e-45, "Got %.18le, expected %.18le\n", double_res, 1.1e-30); + buffer[0] = 0; + double_res = 1; + ret = p_sscanf(buffer, "%lf", &double_res); + ok(ret == -1, "expected 0, got %u\n", ret); + ok(double_res == 1, "Got %lf, expected 1\n", double_res); + /* check strings */ ret = p_sprintf(buffer," %s", pname); ok( ret == 26, "expected 26, got %u\n", ret);