]> granicus.if.org Git - vim/commitdiff
patch 8.2.0039: memory access error when "z=" has no suggestions v8.2.0039
authorBram Moolenaar <Bram@vim.org>
Wed, 25 Dec 2019 12:55:24 +0000 (13:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 25 Dec 2019 12:55:24 +0000 (13:55 +0100)
Problem:    Memory access error when "z=" has no suggestions.
Solution:   Check for negative index.

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

index 9d6df793050d68a46db9ccca031b9d7f022359f3..adf090bbe59febdd4430ec2fe52c139a916640e7 100644 (file)
@@ -3729,7 +3729,8 @@ cleanup_suggestions(
        for (i = keep; i < gap->ga_len; ++i)
            vim_free(stp[i].st_word);
        gap->ga_len = keep;
-       return stp[keep - 1].st_score;
+       if (keep >= 1)
+           return stp[keep - 1].st_score;
     }
     return maxscore;
 }
index 091276b45d6ae1ef420927962881fb5f695c57f1..7080c203b6247fa0fadfd9b721f1a5abc570c1b8 100644 (file)
@@ -241,9 +241,7 @@ func Test_spellsuggest_option_number()
   \ .. "Type number and <Enter> or click with mouse (empty cancels): ", a)
 
   set spell spellsuggest=0
-  " FIXME: the following line is currently commented out as it triggers a
-  " memory error detected in cleanup_suggestions() by asan or valgrind.
-  "call assert_equal("\nSorry, no suggestions", execute('norm z='))
+  call assert_equal("\nSorry, no suggestions", execute('norm z='))
 
   " Unlike z=, function spellsuggest(...) should not be affected by the
   " max number of suggestions (2) set by the 'spellsuggest' option.
index e6f0cf0ab75144e484a6c1444ec0479b24b9dd45..9f7f48a381d93ffb6ccacd79ee3f65075e382f5c 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    39,
 /**/
     38,
 /**/