From 7e152b01a6d5cbfd53a878a85a23baa47529943b Mon Sep 17 00:00:00 2001 From: Jeppe Ledet-Pedersen Date: Fri, 30 May 2025 14:15:10 +0200 Subject: [PATCH 1/2] slash: fix ^W buffer garbling When deleting a word using ^W, only parts of the buffer contents following the word would be shifted, because the length argument passed to memmove was incorrect. When deleting a word mid-buffer, this would garble the contents following the word. Signed-off-by: Jeppe Ledet-Pedersen --- src/slash.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/slash.c b/src/slash.c index 4d9834a..ad52fd1 100644 --- a/src/slash.c +++ b/src/slash.c @@ -1032,17 +1032,18 @@ static void slash_backspace(struct slash *slash) static void slash_delete_word(struct slash *slash) { - int old_cursor = slash->cursor, erased; + size_t old_cursor = slash->cursor; while (slash->cursor > 0 && slash->buffer[slash->cursor-1] == ' ') slash->cursor--; while (slash->cursor > 0 && slash->buffer[slash->cursor-1] != ' ') slash->cursor--; - erased = old_cursor - slash->cursor; - - memmove(slash->buffer + slash->cursor, slash->buffer + old_cursor, erased); - slash->length -= erased; + slash->length -= old_cursor - slash->cursor; + memmove(&slash->buffer[slash->cursor], + &slash->buffer[old_cursor], + slash->length - slash->cursor); + slash->buffer[slash->length] = '\0'; } static void slash_swap(struct slash *slash) From b88bc50b9ddcc479c7f573c81a43e38100c1dcf4 Mon Sep 17 00:00:00 2001 From: Jeppe Ledet-Pedersen Date: Fri, 30 May 2025 14:19:14 +0200 Subject: [PATCH 2/2] slash: fix a couple of indentation errors Signed-off-by: Jeppe Ledet-Pedersen --- src/slash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/slash.c b/src/slash.c index ad52fd1..9b043d5 100644 --- a/src/slash.c +++ b/src/slash.c @@ -1008,7 +1008,8 @@ static void slash_delete(struct slash *slash) if (slash->cursor < slash->length) { slash->length--; memmove(&slash->buffer[slash->cursor], - &slash->buffer[slash->cursor + 1], slash->length - slash->cursor); + &slash->buffer[slash->cursor + 1], + slash->length - slash->cursor); slash->buffer[slash->length] = '\0'; } } @@ -1025,7 +1026,8 @@ static void slash_backspace(struct slash *slash) slash->cursor--; slash->length--; memmove(&slash->buffer[slash->cursor], - &slash->buffer[slash->cursor + 1], slash->length - slash->cursor); + &slash->buffer[slash->cursor + 1], + slash->length - slash->cursor); slash->buffer[slash->length] = '\0'; } }