summaryrefslogtreecommitdiff
path: root/src/list.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-18 14:12:31 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-18 14:12:31 +0200
commitb7c21afef14bba0208f2c40d47c050a004eb2f34 (patch)
treed7ac8993ffa95c8e45240dd873eb04e00235f074 /src/list.c
parentd551d6c268e435e2fbba22775510fbd0a54477f6 (diff)
downloadvim-git-b7c21afef14bba0208f2c40d47c050a004eb2f34.tar.gz
patch 8.2.2781: add() silently skips when adding to null list or blobv8.2.2781
Problem: Add() silently skips when adding to null list or blob. Solution: Give an error in Vim9 script. Allocate blob when it is NULL like with list and dict.
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/list.c b/src/list.c
index 56b2188ff..988b2d982 100644
--- a/src/list.c
+++ b/src/list.c
@@ -2412,22 +2412,33 @@ f_mapnew(typval_T *argvars, typval_T *rettv)
void
f_add(typval_T *argvars, typval_T *rettv)
{
- list_T *l;
- blob_T *b;
-
rettv->vval.v_number = 1; // Default: Failed
if (argvars[0].v_type == VAR_LIST)
{
- if ((l = argvars[0].vval.v_list) != NULL
- && !value_check_lock(l->lv_lock,
- (char_u *)N_("add() argument"), TRUE)
+ list_T *l = argvars[0].vval.v_list;
+
+ if (l == NULL)
+ {
+ if (in_vim9script())
+ emsg(_(e_cannot_add_to_null_list));
+ }
+ else if (!value_check_lock(l->lv_lock,
+ (char_u *)N_("add() argument"), TRUE)
&& list_append_tv(l, &argvars[1]) == OK)
+ {
copy_tv(&argvars[0], rettv);
+ }
}
else if (argvars[0].v_type == VAR_BLOB)
{
- if ((b = argvars[0].vval.v_blob) != NULL
- && !value_check_lock(b->bv_lock,
+ blob_T *b = argvars[0].vval.v_blob;
+
+ if (b == NULL)
+ {
+ if (in_vim9script())
+ emsg(_(e_cannot_add_to_null_blob));
+ }
+ else if (!value_check_lock(b->bv_lock,
(char_u *)N_("add() argument"), TRUE))
{
int error = FALSE;