summaryrefslogtreecommitdiffstats
path: root/src/register.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-03-03 21:11:52 +0000
committerBram Moolenaar <Bram@vim.org>2023-03-03 21:11:52 +0000
commit1c73b65229c25e3c1fd8824ba958f7cc4d604f9c (patch)
tree7608152b1c557f616b3f14e277d2d701c45faf45 /src/register.c
parentf77a7f704ffd0ca1050e82f609c8b8bd61863277 (diff)
patch 9.0.1376: accessing invalid memory with put in Visual block modev9.0.1376
Problem: Accessing invalid memory with put in Visual block mode. Solution: Adjust the cursor column if needed.
Diffstat (limited to 'src/register.c')
-rw-r--r--src/register.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/register.c b/src/register.c
index 4dc0a68fd7..461363be37 100644
--- a/src/register.c
+++ b/src/register.c
@@ -1928,7 +1928,7 @@ do_put(
ptr += yanklen;
// insert block's trailing spaces only if there's text behind
- if ((j < count - 1 || !shortline) && spaces)
+ if ((j < count - 1 || !shortline) && spaces > 0)
{
vim_memset(ptr, ' ', (size_t)spaces);
ptr += spaces;
@@ -2284,6 +2284,15 @@ error:
msgmore(nr_lines);
curwin->w_set_curswant = TRUE;
+ // Make sure the cursor is not after the NUL.
+ int len = (int)STRLEN(ml_get_curline());
+ if (curwin->w_cursor.col > len)
+ {
+ if (cur_ve_flags == VE_ALL)
+ curwin->w_cursor.coladd = curwin->w_cursor.col - len;
+ curwin->w_cursor.col = len;
+ }
+
end:
if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
{