eval: Fix add()

This commit is contained in:
ZyX 2017-12-11 10:34:58 +03:00
parent f4132fb38b
commit 1a961b5750
2 changed files with 5 additions and 4 deletions

View File

@ -6544,11 +6544,11 @@ static void f_abs(typval_T *argvars, typval_T *rettv, FunPtr fptr)
static void f_add(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_add(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {
list_T *l; list_T *l;
rettv->vval.v_number = 1; /* Default: Failed */ rettv->vval.v_number = 1; /* Default: Failed */
if (argvars[0].v_type == VAR_LIST) { if (argvars[0].v_type == VAR_LIST) {
if ((l = argvars[0].vval.v_list) != NULL if (!tv_check_lock(tv_list_locked((l = argvars[0].vval.v_list)),
&& !tv_check_lock(tv_list_locked(l), "add() argument", TV_TRANSLATE)) { N_("add() argument"),
TV_TRANSLATE)) {
tv_list_append_tv(l, &argvars[1]); tv_list_append_tv(l, &argvars[1]);
tv_copy(&argvars[0], rettv); tv_copy(&argvars[0], rettv);
} }

View File

@ -101,7 +101,8 @@ describe('NULL', function()
null_expr_test('is accepted as an empty list by writefile()', null_expr_test('is accepted as an empty list by writefile()',
('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname),
0, {0, {}}) 0, {0, {}})
null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) null_expr_test('makes add() error out', 'add(L, 0)',
'E742: Cannot change value of add() argument', 1)
null_expr_test('makes insert() error out', 'insert(L, 1)', null_expr_test('makes insert() error out', 'insert(L, 1)',
'E742: Cannot change value of insert() argument', 0) 'E742: Cannot change value of insert() argument', 0)
null_expr_test('does not crash remove()', 'remove(L, 0)', null_expr_test('does not crash remove()', 'remove(L, 0)',