scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 524eb5c04a9a74e548c677a277743527e629d284
parent caf9a29321f8a3ef57a0ac5fb3bd42177452efc1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  9 Feb 2023 16:08:02 +0100

libc/printf: Allow printing 0 in numtostr()

The loop didn't ensure at least one iteration and it failed
with the case of a 0 and it didn't print anything in that
case.

Diffstat:
Msrc/libc/stdio/vfprintf.c | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/libc/stdio/vfprintf.c b/src/libc/stdio/vfprintf.c @@ -77,8 +77,11 @@ numtostr(uintmax_t val, int flags, struct conv *conv, char *buf) int base = conv->base, prec = conv->prec; uintmax_t oval = val; - for (*buf = '\0'; val > 0; val /= base) + *buf = '\0'; + do { *--buf = conv->digs[val % base]; + val /= base; + } while (val > 0); while (buf0 - buf < prec) *--buf = '0';