comparison src/list.c @ 24482:3d5a66e478f8 v8.2.2781

patch 8.2.2781: add() silently skips when adding to null list or blob Commit: https://github.com/vim/vim/commit/b7c21afef14bba0208f2c40d47c050a004eb2f34 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 18 14:12:31 2021 +0200 patch 8.2.2781: add() silently skips when adding to null list or blob 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.
author Bram Moolenaar <Bram@vim.org>
date Sun, 18 Apr 2021 14:15:04 +0200
parents 5c6ccab68d1e
children bc1a533148d7
comparison
equal deleted inserted replaced
24481:fbf62b847fe2 24482:3d5a66e478f8
2410 * "add(list, item)" function 2410 * "add(list, item)" function
2411 */ 2411 */
2412 void 2412 void
2413 f_add(typval_T *argvars, typval_T *rettv) 2413 f_add(typval_T *argvars, typval_T *rettv)
2414 { 2414 {
2415 list_T *l;
2416 blob_T *b;
2417
2418 rettv->vval.v_number = 1; // Default: Failed 2415 rettv->vval.v_number = 1; // Default: Failed
2419 if (argvars[0].v_type == VAR_LIST) 2416 if (argvars[0].v_type == VAR_LIST)
2420 { 2417 {
2421 if ((l = argvars[0].vval.v_list) != NULL 2418 list_T *l = argvars[0].vval.v_list;
2422 && !value_check_lock(l->lv_lock, 2419
2423 (char_u *)N_("add() argument"), TRUE) 2420 if (l == NULL)
2421 {
2422 if (in_vim9script())
2423 emsg(_(e_cannot_add_to_null_list));
2424 }
2425 else if (!value_check_lock(l->lv_lock,
2426 (char_u *)N_("add() argument"), TRUE)
2424 && list_append_tv(l, &argvars[1]) == OK) 2427 && list_append_tv(l, &argvars[1]) == OK)
2428 {
2425 copy_tv(&argvars[0], rettv); 2429 copy_tv(&argvars[0], rettv);
2430 }
2426 } 2431 }
2427 else if (argvars[0].v_type == VAR_BLOB) 2432 else if (argvars[0].v_type == VAR_BLOB)
2428 { 2433 {
2429 if ((b = argvars[0].vval.v_blob) != NULL 2434 blob_T *b = argvars[0].vval.v_blob;
2430 && !value_check_lock(b->bv_lock, 2435
2436 if (b == NULL)
2437 {
2438 if (in_vim9script())
2439 emsg(_(e_cannot_add_to_null_blob));
2440 }
2441 else if (!value_check_lock(b->bv_lock,
2431 (char_u *)N_("add() argument"), TRUE)) 2442 (char_u *)N_("add() argument"), TRUE))
2432 { 2443 {
2433 int error = FALSE; 2444 int error = FALSE;
2434 varnumber_T n = tv_get_number_chk(&argvars[1], &error); 2445 varnumber_T n = tv_get_number_chk(&argvars[1], &error);
2435 2446