]> granicus.if.org Git - vim/commitdiff
patch 8.1.0804: crash when setting v:errmsg to empty list v8.1.0804
authorBram Moolenaar <Bram@vim.org>
Thu, 24 Jan 2019 12:58:11 +0000 (13:58 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 24 Jan 2019 12:58:11 +0000 (13:58 +0100)
Problem:    Crash when setting v:errmsg to empty list. (Jaon Franklin)
Solution:   Separate getting value and assigning result.

src/eval.c
src/testdir/test_eval_stuff.vim
src/version.c

index f111dc431205cfb5ec666322e7b0c2135f885a73..efa168eef3967e9a6ab15ed76f0a47e86e4923e0 100644 (file)
@@ -7892,9 +7892,16 @@ set_var(
        {
            if (v->di_tv.v_type == VAR_STRING)
            {
-               vim_free(v->di_tv.vval.v_string);
+               VIM_CLEAR(v->di_tv.vval.v_string);
                if (copy || tv->v_type != VAR_STRING)
-                   v->di_tv.vval.v_string = vim_strsave(tv_get_string(tv));
+               {
+                   char_u *val = tv_get_string(tv);
+
+                   // Careful: when assigning to v:errmsg and tv_get_string()
+                   // causes an error message the variable will alrady be set.
+                   if (v->di_tv.vval.v_string == NULL)
+                       v->di_tv.vval.v_string = vim_strsave(val);
+               }
                else
                {
                    /* Take over the string to avoid an extra alloc/free. */
index c7b970a2c772969e1b08a5b9da1d175aec70b577..f4b35983d9f71d85d0bfff8326c24911b7e6ce2b 100644 (file)
@@ -87,3 +87,10 @@ func Test_readfile_binary()
   bwipe!
   call delete('XReadfile')
 endfunc
+
+func Test_let_errmsg()
+  call assert_fails('let v:errmsg = []', 'E730:')
+  let v:errmsg = ''
+  call assert_fails('let v:errmsg = []', 'E730:')
+  let v:errmsg = ''
+endfunc
index dcbf1c2824ea0375ce2ecac30ad7b4a422fd60a2..8706d9868d4475755addcfdb0616010127865120 100644 (file)
@@ -791,6 +791,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    804,
 /**/
     803,
 /**/