Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mickjc750 committed Nov 6, 2020
1 parent d3b9846 commit d4560c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions test/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit d4560c7

Please sign in to comment.