Skip to content

Commit 1c29943

Browse files
committed
patch 8.1.0499: :2vimgrep causes an ml_get error
Problem: :2vimgrep causes an ml_get error Solution: Pass tomatch pointer instead of value. (Yegappan Lakshmanan)
1 parent d474686 commit 1c29943

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/ex_getln.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ may_do_incsearch_highlighting(
483483
if (search_first_line == 0)
484484
// start at the original cursor position
485485
curwin->w_cursor = is_state->search_start;
486+
else if (search_first_line > curbuf->b_ml.ml_line_count)
487+
{
488+
// start after the last line
489+
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
490+
curwin->w_cursor.col = MAXCOL;
491+
}
486492
else
487493
{
488494
// start at the first line in the range

src/quickfix.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5217,15 +5217,15 @@ vgr_match_buflines(
52175217
char_u *fname,
52185218
buf_T *buf,
52195219
regmmatch_T *regmatch,
5220-
long tomatch,
5220+
long *tomatch,
52215221
int duplicate_name,
52225222
int flags)
52235223
{
52245224
int found_match = FALSE;
52255225
long lnum;
52265226
colnr_T col;
52275227

5228-
for (lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0; ++lnum)
5228+
for (lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; ++lnum)
52295229
{
52305230
col = 0;
52315231
while (vim_regexec_multi(regmatch, curwin, buf, lnum,
@@ -5255,7 +5255,7 @@ vgr_match_buflines(
52555255
break;
52565256
}
52575257
found_match = TRUE;
5258-
if (--tomatch == 0)
5258+
if (--*tomatch == 0)
52595259
break;
52605260
if ((flags & VGR_GLOBAL) == 0
52615261
|| regmatch->endpos[0].lnum > 0)
@@ -5464,7 +5464,7 @@ ex_vimgrep(exarg_T *eap)
54645464
// Try for a match in all lines of the buffer.
54655465
// For ":1vimgrep" look for first match only.
54665466
found_match = vgr_match_buflines(qi, fname, buf, &regmatch,
5467-
tomatch, duplicate_name, flags);
5467+
&tomatch, duplicate_name, flags);
54685468

54695469
if (using_dummy)
54705470
{

src/testdir/test_quickfix.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,21 @@ func Test_vimgrep()
23642364
call XvimgrepTests('l')
23652365
endfunc
23662366

2367+
" Test for incsearch highlighting of the :vimgrep pattern
2368+
" This test used to cause "E315: ml_get: invalid lnum" errors.
2369+
func Test_vimgrep_incsearch()
2370+
enew
2371+
set incsearch
2372+
call test_override("char_avail", 1)
2373+
2374+
call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2375+
let l = getqflist()
2376+
call assert_equal(2, len(l))
2377+
2378+
call test_override("ALL", 0)
2379+
set noincsearch
2380+
endfunc
2381+
23672382
func XfreeTests(cchar)
23682383
call s:setup_commands(a:cchar)
23692384

src/version.c

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

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
499,
795797
/**/
796798
498,
797799
/**/

0 commit comments

Comments
 (0)