From c04d8fdf9259e5e303c8b30120649aafd68a5a52 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Tue, 27 Dec 2022 22:37:07 +0100 Subject: [PATCH] correct issue when using %f with 0 --- fdprintf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fdprintf.c b/fdprintf.c index 1bc1b19..6c06e03 100644 --- a/fdprintf.c +++ b/fdprintf.c @@ -64,7 +64,7 @@ int fdprintf (int fd, const char *fmt, ...) *str++ = c; } else { int t = 0; - char w = '0'; + char w = '0'; int i, sz = 0; void *p = NULL; @@ -97,6 +97,10 @@ int fdprintf (int fd, const char *fmt, ...) break; case 'f': /* float */ f = va_arg (ap, double); + if (f == 0) { + *str++ = '0'; + break; + } if (f < 0) { *str++ = '-'; f = -f; @@ -110,7 +114,7 @@ int fdprintf (int fd, const char *fmt, ...) f *= 10; t--; } - f += 1e-7; + f += 1e-7; if (f >= 10) { f /= 10; t++; -- 2.30.2