changeset 32196:d6771e63521c v9.0.1429

patch 9.0.1429: invalid memory access when ending insert mode Commit: https://github.com/vim/vim/commit/1a08a3e2a584889f19b84a27672134649b73da58 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 26 21:27:24 2023 +0100 patch 9.0.1429: invalid memory access when ending insert mode Problem: Invalid memory access when ending insert mode. Solution: Check if the insert_skip value is valid.
author Bram Moolenaar <Bram@vim.org>
date Sun, 26 Mar 2023 22:30:04 +0200
parents 4bdd2f85a64f
children 7ec34e814188
files src/edit.c src/version.c
diffstat 2 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/edit.c
+++ b/src/edit.c
@@ -2438,12 +2438,12 @@ stop_insert(
      * otherwise CTRL-O w and then <Left> will clear "last_insert".
      */
     ptr = get_inserted();
-    if (did_restart_edit == 0 || (ptr != NULL
-				       && (int)STRLEN(ptr) > new_insert_skip))
+    int added = ptr == NULL ? 0 : (int)STRLEN(ptr) - new_insert_skip;
+    if (did_restart_edit == 0 || added > 0)
     {
 	vim_free(last_insert);
 	last_insert = ptr;
-	last_insert_skip = new_insert_skip;
+	last_insert_skip = added < 0 ? 0 : new_insert_skip;
     }
     else
 	vim_free(ptr);
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1429,
+/**/
     1428,
 /**/
     1427,