zipl/libc: Fix printing zeros in vsnprintf

Printing the number zero (e.g. printf("%u", 0)) currently only gives you
an empty string. This is because the while-do loop to map the number to a
string is only entered when the value is 'true', i.e. non-zero. Fix this
by using do-while instead.

Fixes: 6fe9e6c ("zipl/libc: Introduce vsnprintf")
Signed-off-by: Philipp Rudo <prudo@linux.ibm.com>
Reported-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Philipp Rudo
2020-04-20 15:22:27 +02:00
committed by Jan Höppner
parent 1b65b23b43
commit 454f1427d3

View File

@@ -266,10 +266,10 @@ static char *number(char *buf, char *end, unsigned long val,
/* prepare string in reverse order */
len = 0;
while (val) {
do {
tmp[len++] = vec[val % spec->base];
val /= spec->base;
}
} while (val);
if (len > precision)
precision = len;