From 0622446f091b79da55c5547c35b6bce2c1641f04 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Tue, 22 Aug 2023 10:48:38 +0200 Subject: [PATCH] base: print last character of unterminated strings The last character should only be skipped if a `\0` or `\n` is found. If the string ends without such a character or the maximum line length is hit, we do not skip the last character. Fixes genodelabs/genode#4985 --- repos/base/include/util/print_lines.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/repos/base/include/util/print_lines.h b/repos/base/include/util/print_lines.h index d88b441aeb..49463969bf 100644 --- a/repos/base/include/util/print_lines.h +++ b/repos/base/include/util/print_lines.h @@ -67,17 +67,16 @@ void Genode::print_lines(char const *string, size_t len, FUNC const &func) string += num_indent_chars; size_t line_len = 0; - size_t skip_char = 1; + size_t skip_char = 0; for (; line_len < len; line_len++) { if (string[line_len] == '\0' || string[line_len] == '\n') { line_len++; + skip_char = 1; break; } - if (line_len == MAX_LINE_LEN) { - skip_char = 0; + if (line_len == MAX_LINE_LEN) break; - } } if (!line_len)