diff options
author | Bram Moolenaar <Bram@vim.org> | 2023-03-26 21:27:24 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-03-26 21:27:24 +0100 |
commit | 1a08a3e2a584889f19b84a27672134649b73da58 (patch) | |
tree | 097d180c223e66c3848d2d72ac840637ac6a428d /src/edit.c | |
parent | c174c2e58c9e24a75b189e01143e6d057b84e96e (diff) |
patch 9.0.1429: invalid memory access when ending insert modev9.0.1429
Problem: Invalid memory access when ending insert mode.
Solution: Check if the insert_skip value is valid.
Diffstat (limited to 'src/edit.c')
-rw-r--r-- | src/edit.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/edit.c b/src/edit.c index 84b6eef4b6..c23b0a8556 100644 --- 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); |