mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
4b9e91f0ba
This commit is contained in:
parent
7ad621b6d9
commit
233a173226
@ -20082,9 +20082,15 @@ static void set_var(const char *name, const size_t name_len, typval_T *const tv,
|
|||||||
// prevent changing the type.
|
// prevent changing the type.
|
||||||
if (ht == &vimvarht) {
|
if (ht == &vimvarht) {
|
||||||
if (v->di_tv.v_type == VAR_STRING) {
|
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) {
|
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 {
|
} else {
|
||||||
// Take over the string to avoid an extra alloc/free.
|
// Take over the string to avoid an extra alloc/free.
|
||||||
v->di_tv.vval.v_string = tv->vval.v_string;
|
v->di_tv.vval.v_string = tv->vval.v_string;
|
||||||
|
@ -92,3 +92,10 @@ func Test_nocatch_restore_silent_emsg()
|
|||||||
let c5 = nr2char(screenchar(&lines, 5))
|
let c5 = nr2char(screenchar(&lines, 5))
|
||||||
call assert_equal('wrong', c1 . c2 . c3 . c4 . c5)
|
call assert_equal('wrong', c1 . c2 . c3 . c4 . c5)
|
||||||
endfunc
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user