Skip to content

Commit 2ebcc35

Browse files
k-takatabrammool
authored andcommitted
patch 9.0.0052: "zG" may throw an error if invalid character follows
Problem: "zG" may throw an error if invalid character follows. Solution: Pass the word length to valid_spell_word(). (Ken Takata, closes #10737)
1 parent f754fe6 commit 2ebcc35

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/spellfile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,13 +4371,13 @@ wordtree_alloc(spellinfo_T *spin)
43714371
* Control characters and trailing '/' are invalid. Space is OK.
43724372
*/
43734373
static int
4374-
valid_spell_word(char_u *word)
4374+
valid_spell_word(char_u *word, char_u *end)
43754375
{
43764376
char_u *p;
43774377

4378-
if (enc_utf8 && !utf_valid_string(word, NULL))
4378+
if (enc_utf8 && !utf_valid_string(word, end))
43794379
return FALSE;
4380-
for (p = word; *p != NUL; p += mb_ptr2len(p))
4380+
for (p = word; *p != NUL && p < end; p += mb_ptr2len(p))
43814381
if (*p < ' ' || (p[0] == '/' && p[1] == NUL))
43824382
return FALSE;
43834383
return TRUE;
@@ -4408,7 +4408,7 @@ store_word(
44084408
char_u *p;
44094409

44104410
// Avoid adding illegal bytes to the word tree.
4411-
if (!valid_spell_word(word))
4411+
if (!valid_spell_word(word, word + len))
44124412
return FAIL;
44134413

44144414
(void)spell_casefold(curwin, word, len, foldword, MAXWLEN);
@@ -6211,7 +6211,7 @@ spell_add_word(
62116211
int i;
62126212
char_u *spf;
62136213

6214-
if (!valid_spell_word(word))
6214+
if (!valid_spell_word(word, word + len))
62156215
{
62166216
emsg(_(e_illegal_character_in_word));
62176217
return;

src/testdir/test_spell.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,16 @@ func Test_spell_good_word_invalid()
884884
bwipe!
885885
endfunc
886886

887+
func Test_spell_good_word_slash()
888+
" This caused E1280.
889+
new
890+
norm afoo /
891+
1
892+
norm zG
893+
894+
bwipe!
895+
endfunc
896+
887897
func LoadAffAndDic(aff_contents, dic_contents)
888898
set enc=latin1
889899
set spellfile=

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
52,
738740
/**/
739741
51,
740742
/**/

0 commit comments

Comments
 (0)