]> granicus.if.org Git - vim/commitdiff
patch 8.2.0449: Vim9: crash if return type is invalid v8.2.0449
authorBram Moolenaar <Bram@vim.org>
Thu, 26 Mar 2020 12:15:42 +0000 (13:15 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 26 Mar 2020 12:15:42 +0000 (13:15 +0100)
Problem:    Vim9: crash if return type is invalid. (Yegappan Lakshmanan)
Solution:   Always return some type, not NULL.

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

index 9157a1d492e27df8f7ebe0af9ab1da9282be3d88..9b49e7cbb16a96d1dc0dbdb248ae88a6cd345f4d 100644 (file)
@@ -269,6 +269,9 @@ def Test_return_type_wrong()
   CheckScriptFailure(['def Func(): string', 'return 1', 'enddef'], 'expected string but got number')
   CheckScriptFailure(['def Func(): void', 'return "a"', 'enddef'], 'expected void but got string')
   CheckScriptFailure(['def Func()', 'return "a"', 'enddef'], 'expected void but got string')
+
+  CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
+  CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
 enddef
 
 def Test_arg_type_wrong()
index f1d2f66adcf5a4b3db8be746049dd2f301a14e17..0d7b641793b407dfb406ff4c59ea4c75ebb7d5e4 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    449,
 /**/
     448,
 /**/
index a595580dbe4a6d89ce3a2ad92d4419d40eed1530..dd31092624317fe5ba7fadf67f854015dd5095aa 100644 (file)
@@ -1375,19 +1375,19 @@ parse_type_member(char_u **arg, type_T *type, garray_T *type_list)
            emsg(_("E1007: No white space allowed before <"));
        else
            emsg(_("E1008: Missing <type>"));
-       return NULL;
+       return type;
     }
     *arg = skipwhite(*arg + 1);
 
     member_type = parse_type(arg, type_list);
     if (member_type == NULL)
-       return NULL;
+       return type;
 
     *arg = skipwhite(*arg);
     if (**arg != '>')
     {
        emsg(_("E1009: Missing > after type"));
-       return NULL;
+       return type;
     }
     ++*arg;