aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/eval')
-rw-r--r--src/nvim/eval/funcs.c6
-rw-r--r--src/nvim/eval/typval.c20
2 files changed, 19 insertions, 7 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 1c78e25639..d0f6c178df 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -2201,7 +2201,7 @@ static void f_win_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "exepath()" function
static void f_exepath(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- if (tv_check_for_string(&argvars[0]) == FAIL) {
+ if (tv_check_for_nonempty_string(&argvars[0]) == FAIL) {
return;
}
@@ -2661,9 +2661,9 @@ static void f_fnamemodify(typval_T *argvars, typval_T *rettv, FunPtr fptr)
char buf[NUMBUFLEN];
const char *fname = tv_get_string_chk(&argvars[0]);
const char *const mods = tv_get_string_buf_chk(&argvars[1], buf);
- if (fname == NULL || mods == NULL) {
+ if (fname == NULL) {
fname = NULL;
- } else {
+ } else if (mods != NULL && *mods != NUL) {
len = strlen(fname);
size_t usedlen = 0;
if (*mods != NUL) {
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 6300ce6150..4e845cffdd 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -3146,19 +3146,31 @@ 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.
+// Give an error and return FAIL unless "tv" is a 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) {
+ if (tv->v_type != VAR_STRING) {
EMSG(_(e_stringreq));
return FAIL;
}
return OK;
}
+// Give an error and return FAIL unless "tv" is a non-empty string.
+int tv_check_for_nonempty_string(const typval_T *const tv)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
+{
+ if (tv_check_for_string(tv) == FAIL) {
+ return FAIL;
+ }
+ if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL) {
+ EMSG(_(e_non_empty_string_required));
+ return FAIL;
+ }
+ return OK;
+}
+
/// Get the string value of a "stringish" VimL object.
///
/// @param[in] tv Object to get value of.