From 454f1427d3edcd94c2e25fe7165d392bcc97567a Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 20 Apr 2020 15:22:27 +0200 Subject: [PATCH] zipl/libc: Fix printing zeros in vsnprintf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reported-by: Stefan Haberland Reviewed-by: Jan Höppner Signed-off-by: Jan Höppner --- zipl/boot/libc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zipl/boot/libc.c b/zipl/boot/libc.c index 02c16f6a..3442a86d 100644 --- a/zipl/boot/libc.c +++ b/zipl/boot/libc.c @@ -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;