vim-patch:9.0.0360: crash when invalid line number on :for is ignored

Problem:    Crash when invalid line number on :for is ignored.
Solution:   Do not check breakpoint for non-existing line.
35d21c6830

Test does not fail without the fix in Nvim as Nvim uses 0 when line
number overflows. If it is changed to MAXLNUM then the test does fail
without the fix, but using 0 seems better as E481 is still given.
This commit is contained in:
zeertzjq
2022-09-03 06:46:30 +08:00
parent 05b49ef975
commit 7243b1cbde
2 changed files with 16 additions and 1 deletions

View File

@@ -642,7 +642,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags)
// Check for the next breakpoint at or after the ":while"
// or ":for".
if (breakpoint != NULL) {
if (breakpoint != NULL && lines_ga.ga_len > current_line) {
*breakpoint = dbg_find_breakpoint(getline_equal(fgetline, cookie, getsourceline), fname,
((wcmd_T *)lines_ga.ga_data)[current_line].lnum - 1);
*dbg_tick = debug_tick;

View File

@@ -1,5 +1,8 @@
" Tests for various eval things.
source view_util.vim
source shared.vim
function s:foo() abort
try
return [] == 0
@@ -87,6 +90,18 @@ func Test_for_over_null_string()
let &enc = save_enc
endfunc
func Test_for_invalid_line_count()
let lines =<< trim END
111111111111111111111111 for line in ['one']
endfor
END
call writefile(lines, 'XinvalidFor')
" only test that this doesn't crash
call RunVim([], [], '-u NONE -e -s -S XinvalidFor -c qa')
call delete('XinvalidFor')
endfunc
func Test_readfile_binary()
new
call setline(1, ['one', 'two', 'three'])