comparison src/typval.c @ 24246:35603c7991d7 v8.2.2664

patch 8.2.2664: Vim9: not enough function arguments checked for string Commit: https://github.com/vim/vim/commit/32105ae88f3aa6a6af30336f0bc9f8eb81292cd7 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 27 18:59:25 2021 +0100 patch 8.2.2664: Vim9: not enough function arguments checked for string Problem: Vim9: not enough function arguments checked for string. Solution: Check in balloon functions. Refactor function arguments.
author Bram Moolenaar <Bram@vim.org>
date Sat, 27 Mar 2021 19:00:04 +0100
parents 083f07f99e20
children 8b4159943d9a
comparison
equal deleted inserted replaced
24245:5e22bf689c9f 24246:35603c7991d7
342 342
343 /* 343 /*
344 * Give an error and return FAIL unless "tv" is a string. 344 * Give an error and return FAIL unless "tv" is a string.
345 */ 345 */
346 int 346 int
347 check_for_string(typval_T *tv, int arg) 347 check_for_string_arg(typval_T *args, int idx)
348 { 348 {
349 if (tv->v_type != VAR_STRING) 349 if (args[idx].v_type != VAR_STRING)
350 { 350 {
351 if (arg > 0) 351 if (idx >= 0)
352 semsg(_(e_string_required_for_argument_nr), arg); 352 semsg(_(e_string_required_for_argument_nr), idx + 1);
353 else 353 else
354 emsg(_(e_stringreq)); 354 emsg(_(e_stringreq));
355 return FAIL; 355 return FAIL;
356 } 356 }
357 return OK; 357 return OK;
358 } 358 }
359 359
360 /* 360 /*
361 * Give an error and return FAIL unless "tv" is a non-empty string. 361 * Give an error and return FAIL unless "args[idx]" is a non-empty string.
362 */ 362 */
363 int 363 int
364 check_for_nonempty_string(typval_T *tv, int arg) 364 check_for_nonempty_string_arg(typval_T *args, int idx)
365 { 365 {
366 if (check_for_string(tv, arg) == FAIL) 366 if (check_for_string_arg(args, idx) == FAIL)
367 return FAIL; 367 return FAIL;
368 if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL) 368 if (args[idx].vval.v_string == NULL || *args[idx].vval.v_string == NUL)
369 { 369 {
370 if (arg > 0) 370 if (idx >= 0)
371 semsg(_(e_non_empty_string_required_for_argument_nr), arg); 371 semsg(_(e_non_empty_string_required_for_argument_nr), idx + 1);
372 else 372 else
373 emsg(_(e_non_empty_string_required)); 373 emsg(_(e_non_empty_string_required));
374 return FAIL; 374 return FAIL;
375 } 375 }
376 return OK; 376 return OK;