From cbddfa42748262ac3c4dc65930f40e28a15f05d1 Mon Sep 17 00:00:00 2001 From: Jeppe Ledet-Pedersen Date: Thu, 30 Oct 2025 12:39:54 +0100 Subject: [PATCH 1/2] slash: account for zero termination in line buffer limit Do not write past the end of the buffer for maximum length lines. Signed-off-by: Jeppe Ledet-Pedersen --- src/slash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/slash.c b/src/slash.c index d9f23b2..a8a220c 100644 --- a/src/slash.c +++ b/src/slash.c @@ -1021,7 +1021,8 @@ int slash_refresh(struct slash *slash) static void slash_insert(struct slash *slash, int c) { - if (slash->length >= slash->line_size) + /* We need 1 extra byte for the zero termination */ + if (slash->length + 1 >= slash->line_size) return; memmove(&slash->buffer[slash->cursor + 1], From 7d00711c22161dea66250fa2fd6cd460c9bcf4a5 Mon Sep 17 00:00:00 2001 From: Jeppe Ledet-Pedersen Date: Thu, 30 Oct 2025 12:41:33 +0100 Subject: [PATCH 2/2] slash: remove trailing space after echo output The echo function also inadvertently used printf directly, instead of slash_printf. Signed-off-by: Jeppe Ledet-Pedersen --- src/slash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/slash.c b/src/slash.c index a8a220c..1498381 100644 --- a/src/slash.c +++ b/src/slash.c @@ -1321,10 +1321,13 @@ static int slash_builtin_echo(struct slash *slash) { int i; - for (i = 1; i < slash->argc; i++) - printf("%s ", slash->argv[i]); + for (i = 1; i < slash->argc; i++) { + slash_printf(slash, "%s", slash->argv[i]); + if (i + 1 < slash->argc) + slash_printf(slash, " "); + } - printf("\n"); + slash_printf(slash, "\n"); return SLASH_SUCCESS; }