vim-patch:8.2.3489: ml_get error after search with range

Problem:    ml_get error after search with range.
Solution:   Limit the line number to the buffer line count.
35a319b77f
This commit is contained in:
zeertzjq
2022-04-01 17:12:41 +08:00
parent b8fbd749a9
commit b9454d1676
2 changed files with 17 additions and 2 deletions

View File

@@ -4027,8 +4027,9 @@ static linenr_T get_address(exarg_T *eap, char_u **ptr, cmd_addr_T addr_type, in
// When '/' or '?' follows another address, start from // When '/' or '?' follows another address, start from
// there. // there.
if (lnum != MAXLNUM) { if (lnum > 0 && lnum != MAXLNUM) {
curwin->w_cursor.lnum = lnum; curwin->w_cursor.lnum
= lnum > curbuf->b_ml.ml_line_count ? curbuf->b_ml.ml_line_count : lnum;
} }
// Start a forward search at the end of the line (unless // Start a forward search at the end of the line (unless

View File

@@ -1539,5 +1539,19 @@ func Test_no_last_search_pattern()
call feedkeys("??\<C-T>", 'xt') call feedkeys("??\<C-T>", 'xt')
endfunc endfunc
func Test_search_with_invalid_range()
new
let lines =<< trim END
/\%.v
5/
c
END
call writefile(lines, 'Xrangesearch')
source Xrangesearch
bwipe!
call delete('Xrangesearch')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab