]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2357: Vim9: crash when parsing function return type fails v8.2.2357
authorBram Moolenaar <Bram@vim.org>
Fri, 15 Jan 2021 18:04:32 +0000 (19:04 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 15 Jan 2021 18:04:32 +0000 (19:04 +0100)
Problem:    Vim9: crash when parsing function return type fails.
Solution:   Bail out and set return type to "unknown". (closes #7685)

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index e87c33e909c52d69058bae926c66a89cd4a344ac..049532c69f5c143b7abc079f8ca6628c0a886d59 100644 (file)
@@ -197,6 +197,17 @@ def Test_return_nothing()
   s:nothing->assert_equal(1)
 enddef
 
+def Test_return_invalid()
+  var lines =<< trim END
+    vim9script
+    def Func(): invalid
+      return xxx
+    enddef
+    defcompile
+  END
+  CheckScriptFailure(lines, 'E1010:', 2)
+enddef
+
 func Increment()
   let g:counter += 1
 endfunc
index ded9ef7b0f9d335339fe736355f6b256cc8f6ad1..7ca8186e133a06c9af2da2e11e87775cbdd8840a 100644 (file)
@@ -3886,6 +3886,12 @@ define_function(exarg_T *eap, char_u *name_arg)
        {
            p = ret_type;
            fp->uf_ret_type = parse_type(&p, &fp->uf_type_list, TRUE);
+           if (fp->uf_ret_type == NULL)
+           {
+               fp->uf_ret_type = &t_void;
+               SOURCING_LNUM = lnum_save;
+               goto erret;
+           }
        }
        SOURCING_LNUM = lnum_save;
     }
index 9d217e2a067f4cc42aa7eaef940bb985a66b9129..e7417402fbcb89d30f6b59f5f1a5a3834c7df963 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2357,
 /**/
     2356,
 /**/