aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/typval.c
diff options
context:
space:
mode:
authorFabian <f.vioel@googlemail.com>2021-10-29 04:13:40 +0200
committerGitHub <noreply@github.com>2021-10-28 22:13:40 -0400
commit1dbbaf89bf5d3bcd1edac3af9938c2e2dd18f816 (patch)
tree1b1f9fd16f4405af5fe82744f42165a085d3a121 /src/nvim/eval/typval.c
parentbb79e05f811968b398b3bedf95c012c888b96e44 (diff)
downloadrneovim-1dbbaf89bf5d3bcd1edac3af9938c2e2dd18f816.tar.gz
rneovim-1dbbaf89bf5d3bcd1edac3af9938c2e2dd18f816.tar.bz2
rneovim-1dbbaf89bf5d3bcd1edac3af9938c2e2dd18f816.zip
fix(eval): checking for a non-empty string is too strict (#15987)
Cherry-pick check_for_nonempty_string() from patch vim-8.2.2133 and apply it on the bases of https://github.com/neovim/neovim/pull/13489 https://github.com/vim/vim/commit/2a9d5d386bea8455b37c1accebc45683ec51d6fb
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r--src/nvim/eval/typval.c20
1 files changed, 16 insertions, 4 deletions
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.