Skip to content

Commit ba748c8

Browse files
committed
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Problem: Invalid memory access when using :sc in Ex mode. (Dominique Pelle) Solution: Avoid the column being negative. Also fix a hang in Ex mode.
1 parent 3764076 commit ba748c8

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/ex_cmds.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5288,6 +5288,8 @@ do_sub(exarg_T *eap)
52885288

52895289
getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL);
52905290
curwin->w_cursor.col = regmatch.endpos[0].col - 1;
5291+
if (curwin->w_cursor.col < 0)
5292+
curwin->w_cursor.col = 0;
52915293
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec);
52925294
if (subflags.do_number || curwin->w_p_nu)
52935295
{

src/ex_getln.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,9 +2369,16 @@ getexmodeline(
23692369
if (ga_grow(&line_ga, 40) == FAIL)
23702370
break;
23712371

2372-
/* Get one character at a time. */
2372+
/*
2373+
* Get one character at a time.
2374+
*/
23732375
prev_char = c1;
2374-
c1 = vgetc();
2376+
2377+
/* Check for a ":normal" command and no more characters left. */
2378+
if (ex_normal_busy > 0 && typebuf.tb_len == 0)
2379+
c1 = '\n';
2380+
else
2381+
c1 = vgetc();
23752382

23762383
/*
23772384
* Handle line editing.

src/testdir/test_substitute.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,11 @@ function! Test_substitute_variants()
106106
endfor
107107
endfor
108108
endfunction
109+
110+
func Test_substitute_repeat()
111+
" This caused an invalid memory access.
112+
split Xfile
113+
s/^/x
114+
call feedkeys("Qsc\<CR>y", 'tx')
115+
bwipe!
116+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
374,
767769
/**/
768770
373,
769771
/**/

0 commit comments

Comments
 (0)