Includes feedback from David Gow david@davidgow.net and Piotr Caban.
Signed-off-by: Andrew Eikum aeikum@codeweavers.com --- dlls/msvcrt/printf.h | 9 ++++++++- dlls/msvcrt/tests/printf.c | 12 ++++++++++++ dlls/ucrtbase/tests/printf.c | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h index aeb1290f48f..c34479c5688 100644 --- a/dlls/msvcrt/printf.h +++ b/dlls/msvcrt/printf.h @@ -1050,7 +1050,14 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API flags.LeftAlign = TRUE; flags.FieldLength = -flags.FieldLength; } - } else while (*p >= '0' && *p <= '9') { + } + +#if _MSVCR_VER >= 140 + if (*p >= '0' && *p <= '9') + flags.FieldLength = 0; +#endif + + while (*p >= '0' && *p <= '9') { flags.FieldLength *= 10; flags.FieldLength += *p++ - '0'; } diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c index 06acf4c8450..010cad0ab8f 100644 --- a/dlls/msvcrt/tests/printf.c +++ b/dlls/msvcrt/tests/printf.c @@ -396,6 +396,18 @@ static void test_sprintf( void ) ok(!strcmp(buffer, "string to copy"), "failed: "%s"\n", buffer);
setlocale(LC_ALL, "C"); + + r = p_sprintf(buffer, "%*1d", 1, 3); + ok(r==11, "r = %d\n", r); + ok(!strcmp(buffer, " 3"), "failed: "%s"\n", buffer); + + r = p_sprintf(buffer, "%0*0d", 1, 2); + ok(r==10, "r = %d\n", r); + ok(!strcmp(buffer, "0000000002"), "failed: "%s"\n", buffer); + + r = p_sprintf(buffer, "% *2d", 0, 7); + ok(r==2, "r = %d\n", r); + ok(!strcmp(buffer, " 7"), "failed: "%s"\n", buffer); }
static void test_swprintf( void ) diff --git a/dlls/ucrtbase/tests/printf.c b/dlls/ucrtbase/tests/printf.c index 4f20ccff9a4..51a54426bc4 100644 --- a/dlls/ucrtbase/tests/printf.c +++ b/dlls/ucrtbase/tests/printf.c @@ -845,6 +845,24 @@ static void test_printf_fp(void) } }
+static void test_printf_width_specification(void) +{ + int r; + char buffer[20]; + + r = vsprintf_wrapper(0, buffer, sizeof(buffer), "%0*2d", 1, 3); + ok(r == 2, "r = %d\n", r); + ok(!strcmp(buffer, "03"), "buffer wrong, got=%s\n", buffer); + + r = vsprintf_wrapper(0, buffer, sizeof(buffer), "%*0d", 1, 2); + ok(r == 1, "r = %d\n", r); + ok(!strcmp(buffer, "2"), "buffer wrong, got=%s\n", buffer); + + r = vsprintf_wrapper(0, buffer, sizeof(buffer), "% *2d", 0, 7); + ok(r == 2, "r = %d\n", r); + ok(!strcmp(buffer, " 7"), "buffer wrong, got=%s\n", buffer); +} + START_TEST(printf) { ok(_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL, @@ -862,4 +880,5 @@ START_TEST(printf) test_printf_c99(); test_printf_natural_string(); test_printf_fp(); + test_printf_width_specification(); }
On 8/11/21 23:42, Andrew Eikum wrote:
Includes feedback from David Gow david@davidgow.net and Piotr Caban.
Signed-off-by: Andrew Eikum aeikum@codeweavers.com
Thanks — I can confirm this version fixes Age of Empires IV perfectly.
— David