comparison src/filepath.c @ 25302:4d3c68196d05 v8.2.3188

patch 8.2.3188: Vim9: argument types are not checked at compile time Commit: https://github.com/vim/vim/commit/83494b4ac61898f687d6ef9dce4bad5802fb8e51 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue Jul 20 17:51:51 2021 +0200 patch 8.2.3188: Vim9: argument types are not checked at compile time Problem: Vim9: argument types are not checked at compile time. Solution: Add several more type checks, also at runtime. (Yegappan Lakshmanan, closes #8587)
author Bram Moolenaar <Bram@vim.org>
date Tue, 20 Jul 2021 18:00:06 +0200
parents acda780ffc3e
children e2be9f3c5907
comparison
equal deleted inserted replaced
25301:fe178301fc04 25302:4d3c68196d05
1252 { 1252 {
1253 int options = WILD_SILENT|WILD_USE_NL; 1253 int options = WILD_SILENT|WILD_USE_NL;
1254 expand_T xpc; 1254 expand_T xpc;
1255 int error = FALSE; 1255 int error = FALSE;
1256 1256
1257 if (in_vim9script()
1258 && (check_for_string_arg(argvars, 0) == FAIL
1259 || check_for_opt_bool_arg(argvars, 1) == FAIL
1260 || (argvars[1].v_type != VAR_UNKNOWN
1261 && (check_for_opt_bool_arg(argvars, 2) == FAIL
1262 || (argvars[2].v_type != VAR_UNKNOWN
1263 && check_for_opt_bool_arg(argvars, 3) == FAIL)))))
1264 return;
1265
1257 // When the optional second argument is non-zero, don't remove matches 1266 // When the optional second argument is non-zero, don't remove matches
1258 // for 'wildignore' and don't put matches for 'suffixes' at the end. 1267 // for 'wildignore' and don't put matches for 'suffixes' at the end.
1259 rettv->v_type = VAR_STRING; 1268 rettv->v_type = VAR_STRING;
1260 if (argvars[1].v_type != VAR_UNKNOWN) 1269 if (argvars[1].v_type != VAR_UNKNOWN)
1261 { 1270 {
1316 void 1325 void
1317 f_globpath(typval_T *argvars, typval_T *rettv) 1326 f_globpath(typval_T *argvars, typval_T *rettv)
1318 { 1327 {
1319 int flags = WILD_IGNORE_COMPLETESLASH; 1328 int flags = WILD_IGNORE_COMPLETESLASH;
1320 char_u buf1[NUMBUFLEN]; 1329 char_u buf1[NUMBUFLEN];
1321 char_u *file = tv_get_string_buf_chk(&argvars[1], buf1); 1330 char_u *file;
1322 int error = FALSE; 1331 int error = FALSE;
1323 garray_T ga; 1332 garray_T ga;
1324 int i; 1333 int i;
1334
1335 if (in_vim9script()
1336 && (check_for_string_arg(argvars, 0) == FAIL
1337 || check_for_string_arg(argvars, 1) == FAIL
1338 || check_for_opt_bool_arg(argvars, 2) == FAIL
1339 || (argvars[2].v_type != VAR_UNKNOWN
1340 && (check_for_opt_bool_arg(argvars, 3) == FAIL
1341 || (argvars[3].v_type != VAR_UNKNOWN
1342 && check_for_opt_bool_arg(argvars, 4) == FAIL)))))
1343 return;
1344
1345 file = tv_get_string_buf_chk(&argvars[1], buf1);
1325 1346
1326 // When the optional second argument is non-zero, don't remove matches 1347 // When the optional second argument is non-zero, don't remove matches
1327 // for 'wildignore' and don't put matches for 'suffixes' at the end. 1348 // for 'wildignore' and don't put matches for 'suffixes' at the end.
1328 rettv->v_type = VAR_STRING; 1349 rettv->v_type = VAR_STRING;
1329 if (argvars[2].v_type != VAR_UNKNOWN) 1350 if (argvars[2].v_type != VAR_UNKNOWN)
1447 char_u *p; 1468 char_u *p;
1448 int trim_len = 1; 1469 int trim_len = 1;
1449 1470
1450 if (in_vim9script() 1471 if (in_vim9script()
1451 && (check_for_string_arg(argvars, 0) == FAIL 1472 && (check_for_string_arg(argvars, 0) == FAIL
1452 || (argvars[1].v_type != VAR_UNKNOWN 1473 || check_for_opt_number_arg(argvars, 1) == FAIL))
1453 && check_for_number_arg(argvars, 1) == FAIL)))
1454 return; 1474 return;
1455 1475
1456 if (argvars[1].v_type != VAR_UNKNOWN) 1476 if (argvars[1].v_type != VAR_UNKNOWN)
1457 { 1477 {
1458 trim_len = (int)tv_get_number(&argvars[1]); 1478 trim_len = (int)tv_get_number(&argvars[1]);
2421 char_u buf[NUMBUFLEN]; 2441 char_u buf[NUMBUFLEN];
2422 char_u buf2[NUMBUFLEN]; 2442 char_u buf2[NUMBUFLEN];
2423 int error = FALSE; 2443 int error = FALSE;
2424 2444
2425 if (in_vim9script() 2445 if (in_vim9script()
2426 && (check_for_string_arg(argvars, 1) == FAIL 2446 && (check_for_bool_arg(argvars, 0) == FAIL
2447 || check_for_string_arg(argvars, 1) == FAIL
2427 || check_for_string_arg(argvars, 2) == FAIL 2448 || check_for_string_arg(argvars, 2) == FAIL
2428 || check_for_string_arg(argvars, 3) == FAIL)) 2449 || check_for_string_arg(argvars, 3) == FAIL))
2429 return; 2450 return;
2451
2430 save = (int)tv_get_number_chk(&argvars[0], &error); 2452 save = (int)tv_get_number_chk(&argvars[0], &error);
2431 title = tv_get_string_chk(&argvars[1]); 2453 title = tv_get_string_chk(&argvars[1]);
2432 initdir = tv_get_string_buf_chk(&argvars[2], buf); 2454 initdir = tv_get_string_buf_chk(&argvars[2], buf);
2433 defname = tv_get_string_buf_chk(&argvars[3], buf2); 2455 defname = tv_get_string_buf_chk(&argvars[3], buf2);
2434 2456