From 7bb4e74c38642682cfdd0cb4052adfa5efdd7dd1 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Wed, 9 Dec 2020 12:41:50 +0100 Subject: patch 8.2.2117: some functions use any value as a string Problem: Some functions use any value as a string. Solution: Check that the value is a non-empty string. --- src/typval.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/typval.c') diff --git a/src/typval.c b/src/typval.c index 0e2513aee3..64112e738c 100644 --- a/src/typval.c +++ b/src/typval.c @@ -340,6 +340,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. -- cgit v1.2.3