From 9c301c13d4c3dce27aab04695a6f255d0639b719 Mon Sep 17 00:00:00 2001 From: BanceDev Date: Fri, 6 Sep 2024 14:40:18 -0400 Subject: fixed crash when no history exists yet and polls for history --- src/lush.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lush.c b/src/lush.c index aa1b90f..33f7beb 100644 --- a/src/lush.c +++ b/src/lush.c @@ -195,11 +195,13 @@ static void reprint_buffer(char *buffer, int *last_lines, int *pos, // handle history before doing calculations if (history_pos >= 0) { char *history_line = lush_get_past_command(history_pos); - strncpy(buffer, history_line, BUFFER_SIZE); - free(history_line); - // remove newline from buffer - buffer[strlen(buffer) - 1] = '\0'; - *pos = strlen(buffer); + if (history_line != NULL) { + strncpy(buffer, history_line, BUFFER_SIZE); + free(history_line); + // remove newline from buffer + buffer[strlen(buffer) - 1] = '\0'; + *pos = strlen(buffer); + } } int num_lines = ((strlen(buffer) + strlen(prompt) + 1) / width) + 1; -- cgit v1.2.3-59-g8ed1b