aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-06-04 09:20:59 +0200
committerGitHub <noreply@github.com>2019-06-04 09:20:59 +0200
commit2ae5427b3cfdd20353584299524c650c26f8fd17 (patch)
treef91203398811c754206c8831d03172e47eb2a305 /src/nvim/eval.c
parent58f505dc7432cad76269ee447029eb1ad94b5aeb (diff)
parent5f41ca4013d17a81fcfd0a7b0be0422cb9cc25ec (diff)
downloadrneovim-2ae5427b3cfdd20353584299524c650c26f8fd17.tar.gz
rneovim-2ae5427b3cfdd20353584299524c650c26f8fd17.tar.bz2
rneovim-2ae5427b3cfdd20353584299524c650c26f8fd17.zip
Merge #10113 from janlazo/vim-8.0.1518
vim-patch:8.0.1518,8.1.{2,804}
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;