mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 17:06:30 +00:00
eval: executable(), exepath() accept strings only
Cherry-pick f_executable(), f_exepath(), check_for_string() from patch 8.2.2117.
Rename check_for_string() to tv_check_for_string().
7bb4e74c38
Close https://github.com/neovim/neovim/issues/13485
This commit is contained in:
@@ -95,7 +95,6 @@ PRAGMA_DIAG_POP
|
||||
|
||||
|
||||
static char *e_listarg = N_("E686: Argument of %s must be a List");
|
||||
static char *e_stringreq = N_("E928: String required");
|
||||
static char *e_invalwindow = N_("E957: Invalid window number");
|
||||
|
||||
/// Dummy va_list for passing to vim_snprintf
|
||||
@@ -1877,10 +1876,12 @@ static void f_eventhandler(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
*/
|
||||
static void f_executable(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
const char *name = tv_get_string(&argvars[0]);
|
||||
if (tv_check_for_string(&argvars[0]) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check in $PATH and also check directly if there is a directory name
|
||||
rettv->vval.v_number = os_can_exe(name, NULL, true);
|
||||
rettv->vval.v_number = os_can_exe(tv_get_string(&argvars[0]), NULL, true);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
@@ -1984,10 +1985,13 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
/// "exepath()" function
|
||||
static void f_exepath(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
{
|
||||
const char *arg = tv_get_string(&argvars[0]);
|
||||
if (tv_check_for_string(&argvars[0]) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *path = NULL;
|
||||
|
||||
(void)os_can_exe(arg, &path, true);
|
||||
(void)os_can_exe(tv_get_string(&argvars[0]), &path, true);
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = (char_u *)path;
|
||||
|
@@ -2953,6 +2953,19 @@ float_T tv_get_float(const typval_T *const tv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Give an error and return FAIL unless "tv" is a non-empty string.
|
||||
int tv_check_for_string(const typval_T *const tv)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
|
||||
{
|
||||
if (tv->v_type != VAR_STRING
|
||||
|| tv->vval.v_string == NULL
|
||||
|| *tv->vval.v_string == NUL) {
|
||||
EMSG(_(e_stringreq));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Get the string value of a "stringish" VimL object.
|
||||
///
|
||||
/// @param[in] tv Object to get value of.
|
||||
|
Reference in New Issue
Block a user