From d4560c71540915d7d7c43bbeeb9ef605a240eda7 Mon Sep 17 00:00:00 2001 From: Michael Clift Date: Fri, 6 Nov 2020 14:26:54 +1100 Subject: [PATCH] bugfix --- printf.c | 6 +++--- test/test_suite.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/printf.c b/printf.c index 8a700add..625c2043 100644 --- a/printf.c +++ b/printf.c @@ -231,13 +231,13 @@ static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t ma if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { width--; } - while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) { buf[len++] = '0'; } } + while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) { + buf[len++] = '0'; + } // handle hash if (flags & FLAGS_HASH) { diff --git a/test/test_suite.cpp b/test/test_suite.cpp index 5507c3bd..d80008b4 100644 --- a/test/test_suite.cpp +++ b/test/test_suite.cpp @@ -1503,6 +1503,9 @@ TEST_CASE("misc", "[]" ) { test::sprintf(buffer, "%*sx", -3, "hi"); REQUIRE(!strcmp(buffer, "hi x")); + test::sprintf(buffer, "%-20.5i", 123); + REQUIRE(!strcmp(buffer, "00123 ")); + #ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL test::sprintf(buffer, "%.*g", 2, 0.33333333); REQUIRE(!strcmp(buffer, "0.33"));