Commit 0c6bab93 authored by Andrew Eikum's avatar Andrew Eikum Committed by Alexandre Julliard

msvcrt: Better handle multiple width specifiers.

Includes feedback from David Gow <david@davidgow.net> and Piotr Caban. Signed-off-by: 's avatarAndrew Eikum <aeikum@codeweavers.com> Signed-off-by: 's avatarPiotr Caban <piotr@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent e57e19c2
...@@ -1050,7 +1050,14 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API ...@@ -1050,7 +1050,14 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API
flags.LeftAlign = TRUE; flags.LeftAlign = TRUE;
flags.FieldLength = -flags.FieldLength; 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 *= 10;
flags.FieldLength += *p++ - '0'; flags.FieldLength += *p++ - '0';
} }
......
...@@ -396,6 +396,18 @@ static void test_sprintf( void ) ...@@ -396,6 +396,18 @@ static void test_sprintf( void )
ok(!strcmp(buffer, "string to copy"), "failed: \"%s\"\n", buffer); ok(!strcmp(buffer, "string to copy"), "failed: \"%s\"\n", buffer);
setlocale(LC_ALL, "C"); 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 ) static void test_swprintf( void )
......
...@@ -845,6 +845,24 @@ static void test_printf_fp(void) ...@@ -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) START_TEST(printf)
{ {
ok(_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL, ok(_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL,
...@@ -862,4 +880,5 @@ START_TEST(printf) ...@@ -862,4 +880,5 @@ START_TEST(printf)
test_printf_c99(); test_printf_c99();
test_printf_natural_string(); test_printf_natural_string();
test_printf_fp(); test_printf_fp();
test_printf_width_specification();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment