print: fix padding and fractional accumulation

This commit is contained in:
King Kévin 2018-03-23 09:09:26 +01:00
parent 17a2cc4465
commit 25b0466aee
1 changed files with 2 additions and 0 deletions

View File

@ -341,6 +341,7 @@ static size_t vsnprintf(char** str, size_t* size, const char *format, va_list va
} }
// check padding // check padding
if ('0'==*format) { // padding required if ('0'==*format) { // padding required
padding = 0; // reset padding
format++; // go to padding number format++; // go to padding number
while (*format>='0' && *format<='9') { while (*format>='0' && *format<='9') {
if (padding>UINT32_MAX/10) { // check for overflow if (padding>UINT32_MAX/10) { // check for overflow
@ -362,6 +363,7 @@ static size_t vsnprintf(char** str, size_t* size, const char *format, va_list va
} }
// check fractional // check fractional
if ('.'==*format) { // fractional required if ('.'==*format) { // fractional required
fractional = 0; // reset fractional
format++; // go to fractional number format++; // go to fractional number
while (*format>='0' && *format<='9') { while (*format>='0' && *format<='9') {
if (fractional>UINT32_MAX/10) { // check for overflow if (fractional>UINT32_MAX/10) { // check for overflow