Skip to content

Commit 3f45d67

Browse files
committed
patch 9.0.1363: crash when :def function has :break in skipped block
Problem: Crash when :def function has :break in skipped block. (Ernie Rael) Solution: Don't generate a jump for a skipped :break. (closes #12077)
1 parent 99ad3a8 commit 3f45d67

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/testdir/test_vim9_func.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,31 @@ def Test_wrong_function_name()
166166
delfunc g:Define
167167
enddef
168168

169+
def Test_break_in_skipped_block()
170+
var lines =<< trim END
171+
vim9script
172+
173+
def FixStackFrame(): string
174+
for _ in [2]
175+
var path = 'xxx'
176+
if !!path
177+
if false
178+
break
179+
else
180+
return 'foo'
181+
endif
182+
endif
183+
endfor
184+
return 'xxx'
185+
enddef
186+
187+
disas FixStackFrame
188+
189+
FixStackFrame()
190+
END
191+
v9.CheckScriptSuccess(lines)
192+
enddef
193+
169194
def Test_autoload_name_mismatch()
170195
var dir = 'Xnamedir/autoload'
171196
mkdir(dir, 'pR')

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1363,
698700
/**/
699701
1362,
700702
/**/

src/vim9cmds.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,9 @@ compile_break(char_u *arg, cctx_T *cctx)
14401440
e_break_without_while_or_for, cctx) == FAIL)
14411441
return NULL;
14421442

1443+
if (cctx->ctx_skip == SKIP_YES)
1444+
return arg;
1445+
14431446
if (try_scopes > 0)
14441447
// Inside one or more try/catch blocks we first need to jump to the
14451448
// "finally" or "endtry" to cleanup. Then come to the next JUMP
@@ -1449,7 +1452,7 @@ compile_break(char_u *arg, cctx_T *cctx)
14491452
// Jump to the end of the FOR or WHILE loop. The instruction index will be
14501453
// filled in later.
14511454
if (compile_jump_to_end(el, JUMP_ALWAYS, 0, cctx) == FAIL)
1452-
return FAIL;
1455+
return NULL;
14531456

14541457
return arg;
14551458
}

0 commit comments

Comments
 (0)