]> granicus.if.org Git - vim/commitdiff
patch 8.2.4528: crash when using null_function for a partial v8.2.4528
authorBram Moolenaar <Bram@vim.org>
Tue, 8 Mar 2022 16:52:24 +0000 (16:52 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 8 Mar 2022 16:52:24 +0000 (16:52 +0000)
Problem:    Crash when using null_function for a partial.
Solution:   Don't call fname_trans_sid() with NULL. (closes #9908)

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

index a47dbae27b1f7db15b035753844f63eb465e402c..131413b160e986f62b5d2db4e795fa63c653e331 100644 (file)
@@ -3337,6 +3337,15 @@ def Test_partial_double_nested()
   assert_equal(123, RefRef())
 enddef
 
+def Test_partial_null_function()
+  var lines =<< trim END
+      var d: dict<func> = {f: null_function}
+      var Ref = d.f
+      assert_equal('func', typename(Ref))
+  END
+  v9.CheckDefAndScriptSuccess(lines)
+enddef
+
 " Using "idx" from a legacy global function does not work.
 " This caused a crash when called from legacy context.
 func Test_partial_call_fails()
index 63bb3140a33edb14657136d1d44eeb69ebbc0dbb..f0abaee5f01ef2407854335b9448bf76cc757483 100644 (file)
@@ -5730,7 +5730,6 @@ func_has_abort(
 make_partial(dict_T *selfdict_in, typval_T *rettv)
 {
     char_u     *fname;
-    char_u     *tofree = NULL;
     ufunc_T    *fp;
     char_u     fname_buf[FLEN_FIXED + 1];
     int                error;
@@ -5742,13 +5741,19 @@ make_partial(dict_T *selfdict_in, typval_T *rettv)
     {
        fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string
                                              : rettv->vval.v_partial->pt_name;
-       // Translate "s:func" to the stored function name.
-       fname = fname_trans_sid(fname, fname_buf, &tofree, &error);
-       fp = find_func(fname, FALSE);
-       vim_free(tofree);
+       if (fname != NULL)
+       {
+           char_u      *tofree = NULL;
+
+           // Translate "s:func" to the stored function name.
+           fname = fname_trans_sid(fname, fname_buf, &tofree, &error);
+           fp = find_func(fname, FALSE);
+           vim_free(tofree);
+       }
     }
 
-    if (fp != NULL && (fp->uf_flags & FC_DICT))
+    if ((fp != NULL && (fp->uf_flags & FC_DICT))
+               || (rettv->v_type == VAR_FUNC && rettv->vval.v_string == NULL))
     {
        partial_T       *pt = ALLOC_CLEAR_ONE(partial_T);
 
index 7945910035a233d3f1ac4e774ac6f774ed7dac93..f6aaa79554f07941bd3951d990f294aac7d48d89 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4528,
 /**/
     4527,
 /**/