1
0
Fork 0

fix(printf): ignore 0 flag for integers if precision is specified

Fixes #27
development
Marco Paland 7 years ago
parent 7075d314a0
commit 21a282a2a4

@ -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

@ -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, " "));
}

Loading…
Cancel
Save