mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
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.
This commit is contained in:
11
src/eval.c
11
src/eval.c
@@ -7892,9 +7892,16 @@ set_var(
|
|||||||
{
|
{
|
||||||
if (v->di_tv.v_type == VAR_STRING)
|
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)
|
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
|
else
|
||||||
{
|
{
|
||||||
/* Take over the string to avoid an extra alloc/free. */
|
/* Take over the string to avoid an extra alloc/free. */
|
||||||
|
@@ -87,3 +87,10 @@ func Test_readfile_binary()
|
|||||||
bwipe!
|
bwipe!
|
||||||
call delete('XReadfile')
|
call delete('XReadfile')
|
||||||
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
|
||||||
|
@@ -791,6 +791,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
804,
|
||||||
/**/
|
/**/
|
||||||
803,
|
803,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user