From 4b9e91f0ba02192e4592a5c4a9bdcdd6e9efeb5e Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 24 Jan 2019 13:58:11 +0100 Subject: patch 8.1.0804: crash when setting v:errmsg to empty list Problem: Crash when setting v:errmsg to empty list. (Jaon Franklin) Solution: Separate getting value and assigning result. --- src/eval.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index f111dc431..efa168eef 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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. */ -- cgit v1.2.1