lib: sbi: Fix printc
authorXiang W <wxjstz@126.com>
Sun, 9 Jul 2023 16:02:29 +0000 (00:02 +0800)
committerAnup Patel <anup@brainfault.org>
Wed, 12 Jul 2023 04:32:27 +0000 (10:02 +0530)
Because *out needs to reserve a byte to hold '\0', no more characters
should be added to the buffer when *out has one byte left, and the
buffer size *out_len should not be modified. this patch prevents
the correction of *out_len when *out_len is 1.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_console.c

index adbe2e6b5db01f2dec03351b27539fcd123d6ffb..6915148b1754c2593b681e3794217a15a76deaf1 100644 (file)
@@ -142,10 +142,9 @@ static void printc(char **out, u32 *out_len, char ch)
        if (!out_len || *out_len > 1) {
                *(*out)++ = ch;
                **out = '\0';
+               if (out_len)
+                       --(*out_len);
        }
-
-       if (out_len && *out_len > 0)
-               --(*out_len);
 }
 
 static int prints(char **out, u32 *out_len, const char *string, int width,