0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.0.1144: reading beyond text

Problem:    Reading beyond text.
Solution:   Add strlen_maxlen() and use it.
This commit is contained in:
Bram Moolenaar
2023-01-04 15:56:51 +00:00
parent 7b17eb4b06
commit c32949b077
5 changed files with 30 additions and 2 deletions

View File

@@ -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;