aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--printf.c5
-rw-r--r--test/test_suite.cpp6
2 files changed, 11 insertions, 0 deletions
diff --git a/printf.c b/printf.c
index 9ef669f..a7a3d68 100644
--- a/printf.c
+++ b/printf.c
@@ -551,6 +551,11 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
}
+ // ignore '0' flag when precision is given
+ if (flags & FLAGS_PRECISION) {
+ flags &= ~FLAGS_ZEROPAD;
+ }
+
// convert the integer
if ((*format == 'i') || (*format == 'd')) {
// signed
diff --git a/test/test_suite.cpp b/test/test_suite.cpp
index 99e07b7..45f1abe 100644
--- a/test/test_suite.cpp
+++ b/test/test_suite.cpp
@@ -934,6 +934,12 @@ TEST_CASE("length", "[]" ) {
test::sprintf(buffer, "%20.X", 0U);
REQUIRE(!strcmp(buffer, " "));
+
+ test::sprintf(buffer, "%02.0u", 0U);
+ REQUIRE(!strcmp(buffer, " "));
+
+ test::sprintf(buffer, "%02.0d", 0);
+ REQUIRE(!strcmp(buffer, " "));
}