]> granicus.if.org Git - vim/commitdiff
patch 8.1.1938: may crash when out of memory v8.1.1938
authorBram Moolenaar <Bram@vim.org>
Thu, 29 Aug 2019 19:32:55 +0000 (21:32 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 29 Aug 2019 19:32:55 +0000 (21:32 +0200)
Problem:    May crash when out of memory.
Solution:   Initialize v_type to VAR_UNKNOWN. (Dominique Pelle, closes #4871)

src/userfunc.c
src/version.c

index 7366fc5cd682329b76a4b54ca6e8f2f807e48b6c..3f9171d2e6b9e2ef25d8ee20a908a9f428888ba4 100644 (file)
@@ -1501,6 +1501,10 @@ call_func(
     int                argv_base = 0;
     partial_T  *partial = funcexe->partial;
 
+    // Initialize rettv so that it is safe for caller to invoke clear_tv(rettv)
+    // even when call_func() returns FAIL.
+    rettv->v_type = VAR_UNKNOWN;
+
     // Make a copy of the name, if it comes from a funcref variable it could
     // be changed or deleted in the called function.
     name = len > 0 ? vim_strnsave(funcname, len) : vim_strsave(funcname);
@@ -1530,16 +1534,7 @@ call_func(
        }
     }
 
-    /*
-     * Execute the function if executing and no errors were detected.
-     */
-    if (!funcexe->evaluate)
-    {
-       // Not evaluating, which means the return value is unknown.  This
-       // matters for giving error messages.
-       rettv->v_type = VAR_UNKNOWN;
-    }
-    else if (error == ERROR_NONE)
+    if (error == ERROR_NONE && funcexe->evaluate)
     {
        char_u *rfname = fname;
 
index c6bf6c5c664cdf7740c43d51b5b083b015dde2de..96e0b40bb26f69fca911d98515876ce5adb2ad97 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1938,
 /**/
     1937,
 /**/