Fix SIGSEGV when insert row

This commit is contained in:
Night Kaly 2024-11-12 02:23:06 +00:00
parent 2a0d604c7e
commit 71312ab340
Signed by: night0721
SSH key fingerprint: SHA256:B/hgVwUoBpx5vdNsXl9w8XwZljA9766uk6T4ubZp5HM

4
vip.c
View file

@ -617,7 +617,9 @@ void update_row(row_t *row)
int tabs = 0; int tabs = 0;
for (int j = 0; j < row->size; j++) for (int j = 0; j < row->size; j++)
if (row->chars[j] == '\t') tabs++; if (row->chars[j] == '\t') tabs++;
if (row->render) {
free(row->render); free(row->render);
}
row->render = malloc(row->size + tabs * (TAB_SIZE - 1) + 1); row->render = malloc(row->size + tabs * (TAB_SIZE - 1) + 1);
int idx = 0; int idx = 0;
for (int j = 0; j < row->size; j++) { 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].chars[len] = '\0';
cur_editor->row[at].hl = NULL; cur_editor->row[at].hl = NULL;
cur_editor->row[at].opened_comment = 0; 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]); update_row(&cur_editor->row[at]);
cur_editor->rows++; cur_editor->rows++;