From 7e0ccc3f698c14a3e1db92e89c6f6d0134a483fb Mon Sep 17 00:00:00 2001 From: Lephe Date: Fri, 21 May 2021 22:30:51 +0200 Subject: [PATCH] kprint: do not call Grisu2b with input 0.0 It doesn't generate the expected string "0" for some reason, which causes a freeze somewhere. --- src/kprint/kformat_fp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kprint/kformat_fp.c b/src/kprint/kformat_fp.c index 6e432f5..581a652 100644 --- a/src/kprint/kformat_fp.c +++ b/src/kprint/kformat_fp.c @@ -200,7 +200,7 @@ static void kformat_fp(KFORMAT_ARGS) double v = va_arg(*args, double); digit_buffer[0] = '0'; char *digits = digit_buffer + 1; - int length, e; + int length = 0, e = 0; int is_e = (spec | 0x20) == 'e'; int is_f = (spec | 0x20) == 'f'; @@ -214,7 +214,8 @@ static void kformat_fp(KFORMAT_ARGS) if(special_notation(v, (spec & 0x20) == 0)) return; /* fabs(v) = int(digits) * 10^e */ - grisu2(v, digits, &length, &e); + if(v == 0.0) digits[length++] = '0'; + else grisu2(v, digits, &length, &e); digits[length] = 0; /* In %f and %e, .precision is the number of decimal places; in %g, it