From 71312ab340a849df8c36362377c8782decd6c336 Mon Sep 17 00:00:00 2001 From: night0721 Date: Tue, 12 Nov 2024 02:23:06 +0000 Subject: [PATCH] Fix SIGSEGV when insert row --- vip.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vip.c b/vip.c index 8f4b657..0a50cb1 100644 --- a/vip.c +++ b/vip.c @@ -617,7 +617,9 @@ void update_row(row_t *row) int tabs = 0; for (int j = 0; j < row->size; j++) if (row->chars[j] == '\t') tabs++; - free(row->render); + if (row->render) { + free(row->render); + } row->render = malloc(row->size + tabs * (TAB_SIZE - 1) + 1); int idx = 0; for (int j = 0; j < row->size; j++) { @@ -653,6 +655,8 @@ void insert_row(int at, char *s, size_t len) cur_editor->row[at].chars[len] = '\0'; cur_editor->row[at].hl = NULL; cur_editor->row[at].opened_comment = 0; + cur_editor->row[at].render_size = 0; + cur_editor->row[at].render = NULL; update_row(&cur_editor->row[at]); cur_editor->rows++;