diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-09-11 21:14:20 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-09-11 21:14:20 +0200 |
commit | 35a9a00afcb20897d462a766793ff45534810dc3 (patch) | |
tree | 2706b760e766121610ba642b5d45496861a7a898 /src/normal.c | |
parent | b3bf33a7b227df871834e816c4ce4b2706b56bea (diff) | |
download | vim-git-35a9a00afcb20897d462a766793ff45534810dc3.tar.gz |
patch 8.2.3428: using freed memory when replacingv8.2.3428
Problem: Using freed memory when replacing. (Dhiraj Mishra)
Solution: Get the line pointer after calling ins_copychar().
Diffstat (limited to 'src/normal.c')
-rw-r--r-- | src/normal.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/normal.c b/src/normal.c index 0e1e11801..6620af924 100644 --- a/src/normal.c +++ b/src/normal.c @@ -5099,19 +5099,23 @@ nv_replace(cmdarg_T *cap) { /* * Get ptr again, because u_save and/or showmatch() will have - * released the line. At the same time we let know that the - * line will be changed. + * released the line. This may also happen in ins_copychar(). + * At the same time we let know that the line will be changed. */ - ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); if (cap->nchar == Ctrl_E || cap->nchar == Ctrl_Y) { int c = ins_copychar(curwin->w_cursor.lnum + (cap->nchar == Ctrl_Y ? -1 : 1)); + + ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); if (c != NUL) ptr[curwin->w_cursor.col] = c; } else + { + ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE); ptr[curwin->w_cursor.col] = cap->nchar; + } if (p_sm && msg_silent == 0) showmatch(cap->nchar); ++curwin->w_cursor.col; |