diff options
| author | 2024-09-06 14:40:18 -0400 | |
|---|---|---|
| committer | 2024-09-06 14:40:18 -0400 | |
| commit | 9c301c13d4c3dce27aab04695a6f255d0639b719 (patch) | |
| tree | 2bb4724ccc6ebf657512eb4e589d3903b1f5c5e5 | |
| parent | fixed inability to move cursor between lines (diff) | |
fixed crash when no history exists yet and polls for history
| -rw-r--r-- | src/lush.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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; |
