1
0
Fork 0

fix(printf): fix negative argument precision

Fixes #25
development
Marco Paland 7 years ago
parent f8a2be378d
commit 6dae1687b5

@ -464,7 +464,8 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
precision = _atoi(&format);
}
else if (*format == '*') {
precision = (unsigned int)va_arg(va, int);
const int prec = (int)va_arg(va, int);
precision = prec > 0 ? (unsigned int)prec : 0U;
format++;
}
}

@ -1226,6 +1226,9 @@ TEST_CASE("misc", "[]" ) {
test::sprintf(buffer, "%.*f", 2, 0.33333333);
REQUIRE(!strcmp(buffer, "0.33"));
test::sprintf(buffer, "%.*d", -1, 1);
REQUIRE(!strcmp(buffer, "1"));
test::sprintf(buffer, "%.3s", "foobar");
REQUIRE(!strcmp(buffer, "foo"));

Loading…
Cancel
Save