From 7695433c0511e0cd3c035e17a1ec10d86f30dd40 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Fri, 6 Dec 2019 15:57:09 +0100 Subject: [PATCH] msvcrt: Support mixing length and width in scanf format. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45967 Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcrt/scanf.h | 13 +++++++------ dlls/msvcrt/tests/scanf.c | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index de2a2af9752..da65bf8a6b2 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -197,14 +197,14 @@ _FUNCTION_ { format++; suppress=1; } - /* look for width specification */ - while (_ISDIGIT_(*format)) { - width*=10; - width+=*format++ - '0'; - } - if (width==0) width=-1; /* no width spec seen */ /* read prefix (if any) */ while (!prefix_finished) { + /* look for width specification */ + while (_ISDIGIT_(*format)) { + width *= 10; + width += *format++ - '0'; + } + switch(*format) { case 'h': h_prefix++; break; case 'l': @@ -228,6 +228,7 @@ _FUNCTION_ { } if (!prefix_finished) format++; } + if (width==0) width=-1; /* no width spec seen */ /* read type */ switch(*format) { case 'p': diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 5db9d439351..95fd043e6f0 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -205,6 +205,30 @@ static void test_sscanf( void ) ok(ret == 1, "Wrong number of arguments read: %d\n", ret); ok(result == 0xdead614e, "Wrong number read (%x)\n", result); + result = 0xdeadbeef; + strcpy(buffer,"12345678"); + ret = p_sscanf(buffer, "%02hd", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xdead000c, "Wrong number read (%x)\n", result); + + result = 0xdeadbeef; + strcpy(buffer,"12345678"); + ret = p_sscanf(buffer, "%h02d", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xdead000c, "Wrong number read (%x)\n", result); + + result = 0xdeadbeef; + strcpy(buffer,"12345678"); + ret = p_sscanf(buffer, "%000h02d", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xdead000c, "Wrong number read (%x)\n", result); + + result = 0xdeadbeef; + strcpy(buffer,"12345678"); + ret = p_sscanf(buffer, "%2h0d", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xdead614e, "Wrong number read (%x)\n", result); + result = 0xdeadbeef; ret = p_sscanf(buffer, "%hhd", &result); ok(ret == 1, "Wrong number of arguments read: %d\n", ret);