0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3361: Vim9: crash with nested :while

Problem:    Vim9: crash with nested :while.
Solution:   Handle skipping better. (Naruhiko Nishino, closes #8778)
This commit is contained in:
rbtnn
2021-08-20 20:54:25 +02:00
committed by Bram Moolenaar
parent 5aec755b67
commit d895b1d918
3 changed files with 107 additions and 17 deletions

View File

@@ -2856,6 +2856,89 @@ def Test_for_loop_with_try_continue()
CheckDefAndScriptSuccess(lines) CheckDefAndScriptSuccess(lines)
enddef enddef
def Test_while_skipped_block()
# test skipped blocks at outside of function
var lines =<< trim END
var result = []
var n = 0
if true
n = 1
while n < 3
result += [n]
n += 1
endwhile
else
n = 3
while n < 5
result += [n]
n += 1
endwhile
endif
assert_equal([1, 2], result)
result = []
if false
n = 1
while n < 3
result += [n]
n += 1
endwhile
else
n = 3
while n < 5
result += [n]
n += 1
endwhile
endif
assert_equal([3, 4], result)
END
CheckDefAndScriptSuccess(lines)
# test skipped blocks at inside of function
lines =<< trim END
def DefTrue()
var result = []
var n = 0
if true
n = 1
while n < 3
result += [n]
n += 1
endwhile
else
n = 3
while n < 5
result += [n]
n += 1
endwhile
endif
assert_equal([1, 2], result)
enddef
DefTrue()
def DefFalse()
var result = []
var n = 0
if false
n = 1
while n < 3
result += [n]
n += 1
endwhile
else
n = 3
while n < 5
result += [n]
n += 1
endwhile
endif
assert_equal([3, 4], result)
enddef
DefFalse()
END
CheckDefAndScriptSuccess(lines)
enddef
def Test_while_loop() def Test_while_loop()
var result = '' var result = ''
var cnt = 0 var cnt = 0

View File

@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3361,
/**/ /**/
3360, 3360,
/**/ /**/

View File

@@ -4469,8 +4469,6 @@ compile_subscript(
// dict member: dict[key] // dict member: dict[key]
// string index: text[123] // string index: text[123]
// blob index: blob[123] // blob index: blob[123]
// TODO: more arguments
// TODO: recognize list or dict at runtime
if (generate_ppconst(cctx, ppconst) == FAIL) if (generate_ppconst(cctx, ppconst) == FAIL)
return FAIL; return FAIL;
ppconst->pp_is_const = FALSE; ppconst->pp_is_const = FALSE;
@@ -8267,12 +8265,15 @@ compile_while(char_u *arg, cctx_T *cctx)
// compile "expr" // compile "expr"
if (compile_expr0(&p, cctx) == FAIL) if (compile_expr0(&p, cctx) == FAIL)
return NULL; return NULL;
if (!ends_excmd2(arg, skipwhite(p))) if (!ends_excmd2(arg, skipwhite(p)))
{ {
semsg(_(e_trailing_arg), p); semsg(_(e_trailing_arg), p);
return NULL; return NULL;
} }
if (cctx->ctx_skip != SKIP_YES)
{
if (bool_on_stack(cctx) == FAIL) if (bool_on_stack(cctx) == FAIL)
return FAIL; return FAIL;
@@ -8283,6 +8284,7 @@ compile_while(char_u *arg, cctx_T *cctx)
if (compile_jump_to_end(&scope->se_u.se_while.ws_end_label, if (compile_jump_to_end(&scope->se_u.se_while.ws_end_label,
JUMP_IF_FALSE, cctx) == FAIL) JUMP_IF_FALSE, cctx) == FAIL)
return FAIL; return FAIL;
}
return p; return p;
} }
@@ -8304,6 +8306,8 @@ compile_endwhile(char_u *arg, cctx_T *cctx)
return NULL; return NULL;
} }
cctx->ctx_scope = scope->se_outer; cctx->ctx_scope = scope->se_outer;
if (cctx->ctx_skip != SKIP_YES)
{
unwind_locals(cctx, scope->se_local_count); unwind_locals(cctx, scope->se_local_count);
#ifdef FEAT_PROFILE #ifdef FEAT_PROFILE
@@ -8318,6 +8322,7 @@ compile_endwhile(char_u *arg, cctx_T *cctx)
// And in any jumps for ":break" // And in any jumps for ":break"
compile_fill_jump_to_end(&scope->se_u.se_while.ws_end_label, compile_fill_jump_to_end(&scope->se_u.se_while.ws_end_label,
instr->ga_len, cctx); instr->ga_len, cctx);
}
vim_free(scope); vim_free(scope);