summaryrefslogtreecommitdiff
path: root/src/strings.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-01-04 15:56:51 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-04 15:56:51 +0000
commitc32949b0779106ed5710ae3bffc5053e49083ab4 (patch)
tree14e2027724e250793fe942805c894b278d31321f /src/strings.c
parent7b17eb4b063a234376c1ec909ee293e42cff290c (diff)
downloadvim-git-c32949b0779106ed5710ae3bffc5053e49083ab4.tar.gz
patch 9.0.1144: reading beyond textv9.0.1144
Problem: Reading beyond text. Solution: Add strlen_maxlen() and use it.
Diffstat (limited to 'src/strings.c')
-rw-r--r--src/strings.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/strings.c b/src/strings.c
index edcae6f8a..917426599 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -525,6 +525,19 @@ vim_strcat(char_u *to, char_u *from, size_t tosize)
mch_memmove(to + tolen, from, fromlen + 1);
}
+/*
+ * A version of strlen() that has a maximum length.
+ */
+ size_t
+vim_strlen_maxlen(char *s, size_t maxlen)
+{
+ size_t i;
+ for (i = 0; i < maxlen; ++i)
+ if (s[i] == NUL)
+ break;
+ return i;
+}
+
#if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO)
/*
* Compare two strings, ignoring case, using current locale.
@@ -582,7 +595,7 @@ vim_strnicmp(char *s1, char *s2, size_t len)
* 128 to 255 correctly. It also doesn't return a pointer to the NUL at the
* end of the string.
*/
- char_u *
+ char_u *
vim_strchr(char_u *string, int c)
{
char_u *p;