From f53c2578e79877376259390840ccce56963251c4 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 14 Jul 2018 18:32:40 -0400 Subject: vim-patch:8.0.1575: crash when using virtual replace Problem: Crash when using virtual replace. Solution: Adjust orig_line_count. Add more tests. (Christian Brabandt) https://github.com/vim/vim/commit/63e82db6fc910b2d8f1cd018894e50e8b4448155 --- src/nvim/edit.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/edit.c') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 95c903c90c..4945b2b3c8 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -7486,6 +7486,13 @@ static void ins_del(void) vim_beep(BO_BS); } else { curwin->w_cursor.col = temp; + // Adjust orig_line_count in case more lines have been deleted than + // have been added. That makes sure, that open_line() later + // can access all buffer lines correctly + if (State & VREPLACE_FLAG + && orig_line_count > curbuf->b_ml.ml_line_count) { + orig_line_count = curbuf->b_ml.ml_line_count; + } } } else if (del_char(false) == FAIL) { // delete char under cursor vim_beep(BO_BS); -- cgit From e6127a49db3fbc14f982775856ee7bd29fe29ec6 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 1 Aug 2018 12:09:05 -0400 Subject: edit: temp in ins_del() is const int --- src/nvim/edit.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/edit.c') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 4945b2b3c8..faf0cebea5 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -7475,12 +7475,11 @@ static void ins_shift(int c, int lastc) static void ins_del(void) { - int temp; - - if (stop_arrow() == FAIL) + if (stop_arrow() == FAIL) { return; - if (gchar_cursor() == NUL) { /* delete newline */ - temp = curwin->w_cursor.col; + } + if (gchar_cursor() == NUL) { // delete newline + const int temp = curwin->w_cursor.col; if (!can_bs(BS_EOL) // only if "eol" included || do_join(2, false, true, false, false) == FAIL) { vim_beep(BO_BS); -- cgit From 672449e448e504b0ee1e4f1fea13932c90ae8211 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 7 Aug 2018 12:32:13 -0400 Subject: memline: copy in ml_replace() is bool --- src/nvim/edit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/edit.c') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index faf0cebea5..1da9ae3276 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1766,8 +1766,8 @@ change_indent ( /* We only put back the new line up to the cursor */ new_line[curwin->w_cursor.col] = NUL; - /* Put back original line */ - ml_replace(curwin->w_cursor.lnum, orig_line, FALSE); + // Put back original line + ml_replace(curwin->w_cursor.lnum, orig_line, false); curwin->w_cursor.col = orig_col; /* Backspace from cursor to start of line */ @@ -5770,8 +5770,8 @@ auto_format ( pnew = vim_strnsave(new, len + 2); pnew[len] = ' '; pnew[len + 1] = NUL; - ml_replace(curwin->w_cursor.lnum, pnew, FALSE); - /* remove the space later */ + ml_replace(curwin->w_cursor.lnum, pnew, false); + // remove the space later did_add_space = TRUE; } else /* may remove added space */ -- cgit From a2eff8f15c277795604f03ff0ba5cce71ffde7ec Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 7 Aug 2018 13:16:38 -0400 Subject: edit: did_add_space is bool --- src/nvim/edit.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/nvim/edit.c') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 1da9ae3276..846ff70bd0 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -240,8 +240,8 @@ static int ins_need_undo; /* call u_save() before inserting a char. Set when edit() is called. after that arrow_used is used. */ -static int did_add_space = FALSE; /* auto_format() added an extra space - under the cursor */ +static bool did_add_space = false; // auto_format() added an extra space + // under the cursor static TriState dont_sync_undo = kFalse; // CTRL-G U prevents syncing undo // for the next left/right cursor @@ -5772,10 +5772,11 @@ auto_format ( pnew[len + 1] = NUL; ml_replace(curwin->w_cursor.lnum, pnew, false); // remove the space later - did_add_space = TRUE; - } else - /* may remove added space */ + did_add_space = true; + } else { + // may remove added space check_auto_format(FALSE); + } } check_cursor(); @@ -5796,19 +5797,19 @@ check_auto_format ( if (did_add_space) { cc = gchar_cursor(); - if (!WHITECHAR(cc)) - /* Somehow the space was removed already. */ - did_add_space = FALSE; - else { + if (!WHITECHAR(cc)) { + // Somehow the space was removed already. + did_add_space = false; + } else { if (!end_insert) { inc_cursor(); c = gchar_cursor(); dec_cursor(); } if (c != NUL) { - /* The space is no longer at the end of the line, delete it. */ + // The space is no longer at the end of the line, delete it. del_char(FALSE); - did_add_space = FALSE; + did_add_space = false; } } } -- cgit From 0e4a54a17b92545ce8c4d4ac0212a424bbe990ca Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 7 Aug 2018 13:20:12 -0400 Subject: edit: end_insert in check_auto_format() is bool --- src/nvim/edit.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/nvim/edit.c') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 846ff70bd0..6b131fdb43 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -5703,8 +5703,8 @@ auto_format ( pos = curwin->w_cursor; old = get_cursor_line_ptr(); - /* may remove added space */ - check_auto_format(FALSE); + // may remove added space + check_auto_format(false); /* Don't format in Insert mode when the cursor is on a trailing blank, the * user might insert normal text next. Also skip formatting when "1" is @@ -5775,7 +5775,7 @@ auto_format ( did_add_space = true; } else { // may remove added space - check_auto_format(FALSE); + check_auto_format(false); } } @@ -5787,9 +5787,8 @@ auto_format ( * delete it now. The space must be under the cursor, just after the insert * position. */ -static void -check_auto_format ( - int end_insert /* TRUE when ending Insert mode */ +static void check_auto_format( + bool end_insert // true when ending Insert mode ) { int c = ' '; @@ -6034,8 +6033,8 @@ stop_insert ( } } - /* If a space was inserted for auto-formatting, remove it now. */ - check_auto_format(TRUE); + // If a space was inserted for auto-formatting, remove it now. + check_auto_format(true); /* If we just did an auto-indent, remove the white space from the end * of the line, and put the cursor back. -- cgit From d5e8b3f451120d7b40d72b54d749fbe7b54ca90f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 7 Aug 2018 19:07:54 -0400 Subject: misc: fixpos in del_char() is bool --- src/nvim/edit.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/nvim/edit.c') diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 6b131fdb43..66e764f3a1 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -5807,7 +5807,7 @@ static void check_auto_format( } if (c != NUL) { // The space is no longer at the end of the line, delete it. - del_char(FALSE); + del_char(false); did_add_space = false; } } @@ -6053,10 +6053,12 @@ stop_insert ( if (gchar_cursor() == NUL && curwin->w_cursor.col > 0) --curwin->w_cursor.col; cc = gchar_cursor(); - if (!ascii_iswhite(cc)) + if (!ascii_iswhite(cc)) { break; - if (del_char(TRUE) == FAIL) - break; /* should not happen */ + } + if (del_char(true) == FAIL) { + break; // should not happen + } } if (curwin->w_cursor.lnum != tpos.lnum) curwin->w_cursor = tpos; @@ -6710,8 +6712,8 @@ static void replace_do_bs(int limit_col) * text aligned. */ curwin->w_cursor.col += ins_len; while (vcol > orig_vcols && gchar_cursor() == ' ') { - del_char(FALSE); - ++orig_vcols; + del_char(false); + orig_vcols++; } curwin->w_cursor.col -= ins_len; } @@ -7453,13 +7455,15 @@ static void ins_shift(int c, int lastc) */ if (c == Ctrl_D && (lastc == '0' || lastc == '^') && curwin->w_cursor.col > 0) { - --curwin->w_cursor.col; - (void)del_char(FALSE); /* delete the '^' or '0' */ - /* In Replace mode, restore the characters that '^' or '0' replaced. */ - if (State & REPLACE_FLAG) + curwin->w_cursor.col--; + (void)del_char(false); // delete the '^' or '0' + // In Replace mode, restore the characters that '^' or '0' replaced. + if (State & REPLACE_FLAG) { replace_pop_ins(); - if (lastc == '^') - old_indent = get_indent(); /* remember curr. indent */ + } + if (lastc == '^') { + old_indent = get_indent(); // remember curr. indent + } change_indent(INDENT_SET, 0, TRUE, 0, TRUE); } else change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0, TRUE); @@ -7517,8 +7521,9 @@ static void ins_bs_one(colnr_T *vcolp) if (curwin->w_cursor.lnum != Insstart.lnum || curwin->w_cursor.col >= Insstart.col) replace_do_bs(-1); - } else - (void)del_char(FALSE); + } else { + (void)del_char(false); + } } /// Handle Backspace, delete-word and delete-line in Insert mode. @@ -7782,16 +7787,16 @@ static bool ins_bs(int c, int mode, int *inserted_space_p) else { const bool l_enc_utf8 = enc_utf8; const int l_p_deco = p_deco; - if (l_enc_utf8 && l_p_deco) + if (l_enc_utf8 && l_p_deco) { (void)utfc_ptr2char(get_cursor_pos_ptr(), cpc); - (void)del_char(FALSE); - /* - * If there are combining characters and 'delcombine' is set - * move the cursor back. Don't back up before the base - * character. - */ - if (l_enc_utf8 && l_p_deco && cpc[0] != NUL) + } + (void)del_char(false); + // If there are combining characters and 'delcombine' is set + // move the cursor back. Don't back up before the base + // character. + if (l_enc_utf8 && l_p_deco && cpc[0] != NUL) { inc_cursor(); + } if (revins_chars) { revins_chars--; revins_legal++; -- cgit