summaryrefslogtreecommitdiffstats
path: root/src/list.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-04-01 15:26:58 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-01 15:26:58 +0100
commit22ebd172e48ba060c8a7bae3dbf6480b7596d937 (patch)
treeff1a418ba71300eaf1ddd85e37e682b16ade4958 /src/list.c
parentffe6e646dc6aede3bce062e40256ce0edc64bc08 (diff)
patch 8.2.4662: no error for using out of range list indexv8.2.4662
Problem: No error for using out of range list index. Solution: Check list index at script level like in compiled function. (closes #10051)
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/list.c b/src/list.c
index 666fb5ad61..50bf3afc0f 100644
--- a/src/list.c
+++ b/src/list.c
@@ -760,18 +760,20 @@ list_insert(list_T *l, listitem_T *ni, listitem_T *item)
/*
* Get the list item in "l" with index "n1". "n1" is adjusted if needed.
- * In Vim9, it is at the end of the list, add an item.
+ * In Vim9, it is at the end of the list, add an item if "can_append" is TRUE.
* Return NULL if there is no such item.
*/
listitem_T *
-check_range_index_one(list_T *l, long *n1, int quiet)
+check_range_index_one(list_T *l, long *n1, int can_append, int quiet)
{
- listitem_T *li = list_find_index(l, n1);
+ long orig_n1 = *n1;
+ listitem_T *li = list_find_index(l, n1);
if (li == NULL)
{
// Vim9: Allow for adding an item at the end.
- if (in_vim9script() && *n1 == l->lv_len && l->lv_lock == 0)
+ if (can_append && in_vim9script()
+ && *n1 == l->lv_len && l->lv_lock == 0)
{
list_append_number(l, 0);
li = list_find_index(l, n1);
@@ -779,7 +781,7 @@ check_range_index_one(list_T *l, long *n1, int quiet)
if (li == NULL)
{
if (!quiet)
- semsg(_(e_list_index_out_of_range_nr), *n1);
+ semsg(_(e_list_index_out_of_range_nr), orig_n1);
return NULL;
}
}