]> granicus.if.org Git - vim/commitdiff
patch 8.2.0207: crash when missing member type on list argument v8.2.0207
authorBram Moolenaar <Bram@vim.org>
Tue, 4 Feb 2020 20:54:07 +0000 (21:54 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 4 Feb 2020 20:54:07 +0000 (21:54 +0100)
Problem:    Crash when missing member type on list argument.
Solution:   Check for invalid type. (closes #5572)

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

index fee07083e614b339caf79f3adfe09ee6d660bb84..dc1c0b973fb86c2a69c7852b14ae9a7286d370be 100644 (file)
@@ -160,13 +160,16 @@ def Test_call_default_args()
 enddef
 
 def Test_return_type_wrong()
-  " TODO: why is ! needed for Mac and FreeBSD?
   CheckScriptFailure(['def Func(): number', 'return "a"', 'enddef'], 'expected number but got string')
   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')
 enddef
 
+def Test_arg_type_wrong()
+  CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>')
+enddef
+
 def Test_try_catch()
   let l = []
   try
index 2904ee986acbd6aacb66d9be88a0cb4b867a9fb0..ef1d42d12b14ad08a25ea878177f7512e79dd242 100644 (file)
@@ -2968,6 +2968,11 @@ ex_function(exarg_T *eap)
 
     if (eap->cmdidx == CMD_def)
     {
+       int lnum_save = SOURCING_LNUM;
+
+       // error messages are for the first function line
+       SOURCING_LNUM = sourcing_lnum_top;
+
        // parse the argument types
        ga_init2(&fp->uf_type_list, sizeof(type_T), 5);
 
@@ -2980,16 +2985,23 @@ ex_function(exarg_T *eap)
            fp->uf_arg_types = ALLOC_CLEAR_MULT(type_T *, len);
            if (fp->uf_arg_types != NULL)
            {
-               int i;
+               int     i;
+               type_T  *type;
 
                for (i = 0; i < len; ++ i)
                {
                    p = ((char_u **)argtypes.ga_data)[i];
                    if (p == NULL)
                        // todo: get type from default value
-                       fp->uf_arg_types[i] = &t_any;
+                       type = &t_any;
                    else
-                       fp->uf_arg_types[i] = parse_type(&p, &fp->uf_type_list);
+                       type = parse_type(&p, &fp->uf_type_list);
+                   if (type == NULL)
+                   {
+                       SOURCING_LNUM = lnum_save;
+                       goto errret_2;
+                   }
+                   fp->uf_arg_types[i] = type;
                }
            }
            if (varargs)
@@ -3005,6 +3017,11 @@ ex_function(exarg_T *eap)
                    fp->uf_va_type = &t_any;
                else
                    fp->uf_va_type = parse_type(&p, &fp->uf_type_list);
+               if (fp->uf_va_type == NULL)
+               {
+                   SOURCING_LNUM = lnum_save;
+                   goto errret_2;
+               }
            }
            varargs = FALSE;
        }
index 1b8a0a83b37c6db455d532ddd5c6cdcdc3556b38..be1bf33705b08a12f1735c58a9114b9075ef1283 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    207,
 /**/
     206,
 /**/