Problem: Reading beyond text.
Solution: Add strlen_maxlen() and use it.
{
char_u *tofree = NULL;
- if (maxlen > 0 && STRLEN(p) > (size_t)maxlen)
+ if (maxlen > 0 && vim_strlen_maxlen((char *)p, (size_t)maxlen)
+ >= (size_t)maxlen)
{
tofree = vim_strnsave(p, (size_t)maxlen);
p = tofree;
void del_trailing_spaces(char_u *ptr);
void vim_strncpy(char_u *to, char_u *from, size_t len);
void vim_strcat(char_u *to, char_u *from, size_t tosize);
+size_t vim_strlen_maxlen(char *s, size_t maxlen);
int vim_stricmp(char *s1, char *s2);
int vim_strnicmp(char *s1, char *s2, size_t len);
char_u *vim_strchr(char_u *string, int c);
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.
* 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;
call assert_fails('call getcompletion("abc", [])', 'E1174:')
endfunc
+func Test_multibyte_expression()
+ " This was using uninitialized memory.
+ let lines =<< trim END
+ set verbose=6
+ norm @=ٷ
+ qall!
+ END
+ call writefile(lines, 'XmultiScript', 'D')
+ call RunVim('', '', '-u NONE -n -e -s -S XmultiScript')
+endfunc
+
" Test for getcompletion() with "fuzzy" in 'wildoptions'
func Test_getcompletion_wildoptions()
let save_wildoptions = &wildoptions
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1144,
/**/
1143,
/**/