comparison src/evalvars.c @ 21206:caab594592cc v8.2.1154

patch 8.2.1154: Vim9: crash when using imported function Commit: https://github.com/vim/vim/commit/c620c055ce8505596a7208ba696a32b8a3be4f4b Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jul 8 15:16:19 2020 +0200 patch 8.2.1154: Vim9: crash when using imported function Problem: Vim9: crash when using imported function. Solution: Check for a function type. Set the script context when calling a function. (closes #6412)
author Bram Moolenaar <Bram@vim.org>
date Wed, 08 Jul 2020 15:30:04 +0200
parents 951aad18b1af
children 6a4806e326dd
comparison
equal deleted inserted replaced
21205:d7f16d42548f 21206:caab594592cc
2373 int verbose, // may give error message 2373 int verbose, // may give error message
2374 int no_autoload) // do not use script autoloading 2374 int no_autoload) // do not use script autoloading
2375 { 2375 {
2376 int ret = OK; 2376 int ret = OK;
2377 typval_T *tv = NULL; 2377 typval_T *tv = NULL;
2378 int foundFunc = FALSE;
2378 dictitem_T *v; 2379 dictitem_T *v;
2379 int cc; 2380 int cc;
2380 2381
2381 // truncate the name, so that we can use strcmp() 2382 // truncate the name, so that we can use strcmp()
2382 cc = name[len]; 2383 cc = name[len];
2400 import = find_imported(p, 0, NULL); 2401 import = find_imported(p, 0, NULL);
2401 2402
2402 // imported variable from another script 2403 // imported variable from another script
2403 if (import != NULL) 2404 if (import != NULL)
2404 { 2405 {
2405 scriptitem_T *si = SCRIPT_ITEM(import->imp_sid); 2406 if (import->imp_funcname != NULL)
2406 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) 2407 {
2408 foundFunc = TRUE;
2409 if (rettv != NULL)
2410 {
2411 rettv->v_type = VAR_FUNC;
2412 rettv->vval.v_string = vim_strsave(import->imp_funcname);
2413 }
2414 }
2415 else
2416 {
2417 scriptitem_T *si = SCRIPT_ITEM(import->imp_sid);
2418 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
2407 + import->imp_var_vals_idx; 2419 + import->imp_var_vals_idx;
2408 tv = sv->sv_tv; 2420 tv = sv->sv_tv;
2409 } 2421 }
2410 } 2422 }
2411 2423 }
2412 if (tv == NULL) 2424
2413 { 2425 if (!foundFunc)
2414 if (rettv != NULL && verbose) 2426 {
2415 semsg(_(e_undefvar), name); 2427 if (tv == NULL)
2416 ret = FAIL; 2428 {
2417 } 2429 if (rettv != NULL && verbose)
2418 else if (rettv != NULL) 2430 semsg(_(e_undefvar), name);
2419 copy_tv(tv, rettv); 2431 ret = FAIL;
2432 }
2433 else if (rettv != NULL)
2434 copy_tv(tv, rettv);
2435 }
2420 2436
2421 name[len] = cc; 2437 name[len] = cc;
2422 2438
2423 return ret; 2439 return ret;
2424 } 2440 }