Module: wine Branch: master Commit: 7695433c0511e0cd3c035e17a1ec10d86f30dd40 URL: https://source.winehq.org/git/wine.git/?a=commit;h=7695433c0511e0cd3c035e17a...
Author: Piotr Caban piotr@codeweavers.com Date: Fri Dec 6 15:57:09 2019 +0100
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 piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
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 de2a2af975..da65bf8a6b 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 5db9d43935..95fd043e6f 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);