// no '<' rule used
i += k - 1;
z = 0;
- while (*s != NUL && s[1] != NUL && reslen < MAXWLEN)
+ while (*s != NUL && s[1] != NUL && reslen < MAXWLEN - 1)
{
if (reslen == 0 || res[reslen - 1] != *s)
res[reslen++] = *s;
c = *s;
if (strstr((char *)pf, "^^") != NULL)
{
- if (c != NUL)
+ if (c != NUL && reslen < MAXWLEN - 1)
res[reslen++] = c;
STRMOVE(word, word + i + 1);
i = 0;
if (z0 == 0)
{
- if (k && !p0 && reslen < MAXWLEN && c != NUL
+ if (k && !p0 && reslen < MAXWLEN - 1 && c != NUL
&& (!slang->sl_collapse || reslen == 0
|| res[reslen - 1] != c))
// condense only double letters
let &rtp = save_rtp
endfunc
+" An over-length soundfold() argument must not overflow the MAXWLEN result
+" buffer in the single-byte branch of spell_soundfold_sal().
+func Test_spellfile_soundfold_sal_overflow()
+ let save_enc = &encoding
+ set encoding=latin1
+ " A SAL map that appends without collapsing, so the result is not shorter
+ " than the input.
+ call writefile(['SET ISO8859-1', 'SAL collapse_result false',
+ \ 'SAL a aaaa', 'SAL b bbbb'], 'Xsal.aff')
+ call writefile(['2', 'hello', 'world'], 'Xsal.dic')
+ mkspell! Xsal Xsal
+ set spl=Xsal.latin1.spl spell
+
+ " 253 input characters hit the buffer boundary; the result must not exceed
+ " MAXWLEN - 1.
+ call assert_true(strlen(soundfold(repeat('a', 253))) <= 253)
+
+ set nospell spl& spelllang&
+ call delete('Xsal.aff')
+ call delete('Xsal.dic')
+ call delete('Xsal.latin1.spl')
+ let &encoding = save_enc
+endfunc
+
" Test for format errors in suggest file
func Test_sugfile_format_error()
let save_rtp = &rtp