diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-12-09 12:41:50 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-12-09 12:41:50 +0100 |
commit | 7bb4e74c38642682cfdd0cb4052adfa5efdd7dd1 (patch) | |
tree | 87b6644c08d544bae227365d78c1a7c11c611a6d /src/typval.c | |
parent | 2c78a772fdb5f6a16d16a47e7f218051c4dcb845 (diff) |
patch 8.2.2117: some functions use any value as a stringv8.2.2117
Problem: Some functions use any value as a string.
Solution: Check that the value is a non-empty string.
Diffstat (limited to 'src/typval.c')
-rw-r--r-- | src/typval.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/typval.c b/src/typval.c index 0e2513aee3..64112e738c 100644 --- a/src/typval.c +++ b/src/typval.c @@ -341,6 +341,22 @@ tv_get_float(typval_T *varp) #endif /* + * Give an error and return FAIL unless "tv" is a non-empty string. + */ + int +check_for_string(typval_T *tv) +{ + 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 variable. * If it is a Number variable, the number is converted into a string. * tv_get_string() uses a single, static buffer. YOU CAN ONLY USE IT ONCE! |