From: Piotr Caban Subject: [PATCH] msvcrt: Update round_limb on first limb length change in printf. Message-Id: <80275d4b-21c3-8fac-2509-e0afd3d09ec3@codeweavers.com> Date: Sat, 10 Jul 2021 20:38:16 +0200 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51435 Signed-off-by: Piotr Caban --- dlls/msvcrt/printf.h | 14 ++++++++++++++ dlls/ucrtbase/tests/printf.c | 1 + 2 files changed, 15 insertions(+) diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h index c6c074de795..d6b945e8ac7 100644 --- a/dlls/msvcrt/printf.h +++ b/dlls/msvcrt/printf.h @@ -704,11 +704,25 @@ static inline int FUNC_NAME(pf_output_fp)(FUNC_NAME(puts_clbk) pf_puts, void *pu if(i != first_limb_len) { first_limb_len = i; radix_pos++; + + round_pos++; + if (round_pos == LIMB_DIGITS) + { + round_pos = 0; + round_limb++; + } } } else if(i == b->e) { first_limb_len = 1; radix_pos++; b->e++; + + round_pos++; + if (round_pos == LIMB_DIGITS) + { + round_pos = 0; + round_limb++; + } } } } diff --git a/dlls/ucrtbase/tests/printf.c b/dlls/ucrtbase/tests/printf.c index 96241b22cf0..588e579cc7e 100644 --- a/dlls/ucrtbase/tests/printf.c +++ b/dlls/ucrtbase/tests/printf.c @@ -819,6 +819,7 @@ static void test_printf_fp(void) { "%.0f", 0.5, { "1", NULL, NULL, NULL, "0" }, {NULL, NULL, NULL, NULL, "1" }}, { "%.0f", 1.5, { "2" }}, { "%.0f", 2.5, { "3", NULL, NULL, NULL, "2" }, {NULL, NULL, NULL, NULL, "3" }}, + { "%g", 9.999999999999999e-5, { "0.0001" }}, }; const char *res = NULL;