aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar BanceDev 2024-09-06 14:40:18 -0400
committerGravatar BanceDev 2024-09-06 14:40:18 -0400
commit9c301c13d4c3dce27aab04695a6f255d0639b719 (patch)
tree2bb4724ccc6ebf657512eb4e589d3903b1f5c5e5
parentfixed inability to move cursor between lines (diff)
fixed crash when no history exists yet and polls for history
-rw-r--r--src/lush.c12
1 files 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;