From fddda835a28bbc52a8d8450395a3e57e181782a8 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 26 Jun 2024 21:47:15 +0200 Subject: LibC: Fix regression in printf printf did not write out anything for %d when the value was zero. --- userland/libc/stdio/vfprintf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'userland/libc/stdio') diff --git a/userland/libc/stdio/vfprintf.c b/userland/libc/stdio/vfprintf.c index 2ba3e2c..d384c1d 100644 --- a/userland/libc/stdio/vfprintf.c +++ b/userland/libc/stdio/vfprintf.c @@ -28,8 +28,13 @@ int fprint_num(FILE *f, long long n, int base, char *char_set, int prefix, n *= -1; } - for (; n != 0 && i < 32; i++, n /= base) - str[i] = char_set[(n % base)]; + if (0 == n) { + str[i] = char_set[0]; + i++; + } else { + for (; n != 0 && i < 32; i++, n /= base) + str[i] = char_set[(n % base)]; + } if (is_signed) { str[i] = '-'; -- cgit v1.2.3