[PATCH] msvcrt: The '*' character should be interpreted as the beginning of the width specification

Andrew Eikum aeikum at codeweavers.com
Fri Nov 5 13:49:21 CDT 2021


Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
---

For example,

    "%*0d", 1, ...

becomes

    "%10d", ...

i.e. prints ten digits.

 dlls/msvcrt/printf.h       |  4 +++-
 dlls/msvcrt/tests/printf.c | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h
index aeb1290f48f..40a8a13d861 100644
--- a/dlls/msvcrt/printf.h
+++ b/dlls/msvcrt/printf.h
@@ -1050,7 +1050,9 @@ 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') {
+        }
+
+        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..0dd25c3ba8b 100644
--- a/dlls/msvcrt/tests/printf.c
+++ b/dlls/msvcrt/tests/printf.c
@@ -395,6 +395,18 @@ static void test_sprintf( void )
     ok(r==14, "r = %d\n", r);
     ok(!strcmp(buffer, "string to copy"), "failed: \"%s\"\n", buffer);
 
+    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);
+
     setlocale(LC_ALL, "C");
 }
 
-- 
2.33.1




More information about the wine-devel mailing list