]> granicus.if.org Git - vim/commitdiff
patch 8.2.2330: Vim9: crash when using :trow in a not executed block v8.2.2330
authorBram Moolenaar <Bram@vim.org>
Mon, 11 Jan 2021 19:17:34 +0000 (20:17 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 11 Jan 2021 19:17:34 +0000 (20:17 +0100)
Problem:    Vim9: crash when using :trow in a not executed block.
Solution:   Don't generate the instruction when skipping. (closes #7659)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 1066a1d43e5d84dca1c1d21ba4ecac75ab7e3f51..d567de75f815518d9e214a156edbcd0f373b5eff 100644 (file)
@@ -324,7 +324,7 @@ func g:NoSuchFunc()
   echo 'none'
 endfunc
 
-def Test_try_catch()
+def Test_try_catch_throw()
   var l = []
   try # comment
     add(l, '1')
@@ -558,6 +558,12 @@ def Test_try_catch()
   assert_equal(411, n)
 enddef
 
+def Test_throw_skipped()
+  if 0
+    throw dontgethere
+  endif
+enddef
+
 def DeletedFunc(): list<any>
   return ['delete me']
 enddef
index 2a6e1daa01cc99ef9d1a14b839f61a0a4ecb4036..0a3cd54a91548685bf76e7469fb0b6ecc5842e34 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2330,
 /**/
     2329,
 /**/
index bcbc57dd1247c40d464c85c3ac30b18d337987c1..0064bd20550ca04345bc19ceabc83d95533b7cd3 100644 (file)
@@ -474,8 +474,10 @@ may_generate_2STRING(int offset, cctx_T *cctx)
     isn_T      *isn;
     isntype_T  isntype = ISN_2STRING;
     garray_T   *stack = &cctx->ctx_type_stack;
-    type_T     **type = ((type_T **)stack->ga_data) + stack->ga_len + offset;
+    type_T     **type;
 
+    RETURN_OK_IF_SKIP(cctx);
+    type = ((type_T **)stack->ga_data) + stack->ga_len + offset;
     switch ((*type)->tt_type)
     {
        // nothing to be done
@@ -7461,6 +7463,8 @@ compile_throw(char_u *arg, cctx_T *cctx UNUSED)
 
     if (compile_expr0(&p, cctx) == FAIL)
        return NULL;
+    if (cctx->ctx_skip == SKIP_YES)
+       return p;
     if (may_generate_2STRING(-1, cctx) == FAIL)
        return NULL;
     if (generate_instr_drop(cctx, ISN_THROW, 1) == NULL)