]> granicus.if.org Git - vim/commitdiff
patch 8.2.4563: "z=" in Visual mode may go beyond the end of the line v8.2.4563
authorBram Moolenaar <Bram@vim.org>
Sun, 13 Mar 2022 20:12:25 +0000 (20:12 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 13 Mar 2022 20:12:25 +0000 (20:12 +0000)
Problem:    "z=" in Visual mode may go beyond the end of the line.
Solution:   Adjust "badlen".

src/spellsuggest.c
src/testdir/test_spell.vim
src/version.c

index ba3aaf349d476dfd4133fdac76bef4e72be7dfbb..3be917f868a01eebfd23789b577c2b125fca4bef 100644 (file)
@@ -506,6 +506,10 @@ spell_suggest(int count)
            curwin->w_cursor.col = VIsual.col;
        ++badlen;
        end_visual_mode();
+       // make sure we don't include the NUL at the end of the line
+       line = ml_get_curline();
+       if (badlen > STRLEN(line) - curwin->w_cursor.col)
+           badlen = STRLEN(line) - curwin->w_cursor.col;
     }
     // Find the start of the badly spelled word.
     else if (spell_move_to(curwin, FORWARD, TRUE, TRUE, NULL) == 0
index e6f535be14604784b20998b390604a8220ba22a7..804c5dede78ed681beb67739a4cb1c631121dd39 100644 (file)
@@ -456,6 +456,21 @@ func Test_spellsuggest_timeout()
   call assert_fails('set spellsuggest=timeout:--9', 'E474:')
 endfunc
 
+func Test_spellsuggest_visual_end_of_line()
+  let enc_save = &encoding
+  set encoding=iso8859
+
+  " This was reading beyond the end of the line.
+  norm R00000000000
+  sil norm \160
+  sil! norm \16i00000)
+  sil! norm \16i00000)
+  call feedkeys("\<CR>")
+  norm z=
+
+  let &encoding = enc_save
+endfunc
+
 func Test_spellinfo()
   new
   let runtime = substitute($VIMRUNTIME, '\\', '/', 'g')
index 7ac37a41f496f35f0017b0ed479ea291144d4b6b..e5ff441653d809f347e99e95f051aa7a34a1824c 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4563,
 /**/
     4562,
 /**/