diff src/ops.c @ 30295:da023a22d73e v9.0.0483

patch 9.0.0483: illegal memory access when replacing in virtualedit mode Commit: https://github.com/vim/vim/commit/c249913edc35c0e666d783bfc21595cf9f7d9e0d Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 16 22:16:59 2022 +0100 patch 9.0.0483: illegal memory access when replacing in virtualedit mode Problem: Illegal memory access when replacing in virtualedit mode. Solution: Check for replacing NUL after Tab.
author Bram Moolenaar <Bram@vim.org>
date Fri, 16 Sep 2022 23:30:04 +0200
parents d45ee1f829ba
children 1cbb01bc75c3
line wrap: on
line diff
--- a/src/ops.c
+++ b/src/ops.c
@@ -1173,6 +1173,8 @@ op_replace(oparg_T *oap, int c)
 
 	while (LTOREQ_POS(curwin->w_cursor, oap->end))
 	{
+	    int done = FALSE;
+
 	    n = gchar_cursor();
 	    if (n != NUL)
 	    {
@@ -1186,6 +1188,7 @@ op_replace(oparg_T *oap, int c)
 		    if (curwin->w_cursor.lnum == oap->end.lnum)
 			oap->end.col += new_byte_len - old_byte_len;
 		    replace_character(c);
+		    done = TRUE;
 		}
 		else
 		{
@@ -1204,10 +1207,15 @@ op_replace(oparg_T *oap, int c)
 			if (curwin->w_cursor.lnum == oap->end.lnum)
 			    getvpos(&oap->end, end_vcol);
 		    }
-		    PBYTE(curwin->w_cursor, c);
+		    // with "coladd" set may move to just after a TAB
+		    if (gchar_cursor() != NUL)
+		    {
+			PBYTE(curwin->w_cursor, c);
+			done = TRUE;
+		    }
 		}
 	    }
-	    else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum)
+	    if (!done && virtual_op && curwin->w_cursor.lnum == oap->end.lnum)
 	    {
 		int virtcols = oap->end.coladd;