diff options
| author | Xiang W <[email protected]> | 2023-07-10 00:03:26 +0800 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2023-07-12 10:37:43 +0530 |
| commit | a73982d7376a71cf6e230b255069da46fe2becc9 (patch) | |
| tree | 90a9f12f6ea6f4323de3fe2637826f3617f5b578 | |
| parent | ff43168137a4890fe65460c1506fdf08c26bebad (diff) | |
lib: sbi: Fix missing '\0' when buffer szie equal 1
Fix special case: sbi_snprintf(out, out_len, ...) when out_len equal
1, The previous code will not fill the buffer with any char.
Signed-off-by: Xiang W <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
| -rw-r--r-- | lib/sbi/sbi_console.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 07a90452..2b3b0a3f 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -271,6 +271,12 @@ static int print(char **out, u32 *out_len, const char *format, va_list args) out_len = &console_tbuf_len; } + /* handle special case: *out_len == 1*/ + if (out) { + if(!out_len || *out_len) + **out = '\0'; + } + for (; *format != 0; ++format) { width = flags = 0; if (use_tbuf) |
