aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-06-03 22:01:48 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-06-03 23:12:23 -0400
commit233a173226112adc9b8fed336fa03c3b32c3675f (patch)
tree375ac541a3e798129eec94e0ed8ac87df6199178 /src/nvim/eval.c
parent7ad621b6d924ef912a4c4c7e64175213dc82a16f (diff)
downloadrneovim-233a173226112adc9b8fed336fa03c3b32c3675f.tar.gz
rneovim-233a173226112adc9b8fed336fa03c3b32c3675f.tar.bz2
rneovim-233a173226112adc9b8fed336fa03c3b32c3675f.zip
vim-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. https://github.com/vim/vim/commit/4b9e91f0ba02192e4592a5c4a9bdcdd6e9efeb5e
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index a4606f76f3..998d0568ce 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -20082,9 +20082,15 @@ static void set_var(const char *name, const size_t name_len, typval_T *const tv,
// prevent changing the type.
if (ht == &vimvarht) {
if (v->di_tv.v_type == VAR_STRING) {
- xfree(v->di_tv.vval.v_string);
+ XFREE_CLEAR(v->di_tv.vval.v_string);
if (copy || tv->v_type != VAR_STRING) {
- v->di_tv.vval.v_string = (char_u *)xstrdup(tv_get_string(tv));
+ const char *const 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 = (char_u *)xstrdup(val);
+ }
} else {
// Take over the string to avoid an extra alloc/free.
v->di_tv.vval.v_string = tv->vval.v_string;