]> granicus.if.org Git - vim/commitdiff
patch 8.2.0387: error for possible NULL argument to qsort() v8.2.0387
authorBram Moolenaar <Bram@vim.org>
Sun, 15 Mar 2020 17:15:03 +0000 (18:15 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 15 Mar 2020 17:15:03 +0000 (18:15 +0100)
Problem:    Error for possible NULL argument to qsort().
Solution:   Don't call qsort() when there is nothing to sort. (Dominique
            Pelle, closes #5780)

src/spellsuggest.c
src/version.c

index fdd549e47553616f851042d0f0c86bac837874e1..267a4a58c502ce688c78faff53b3e650448e9e4d 100644 (file)
@@ -3719,17 +3719,22 @@ cleanup_suggestions(
     suggest_T   *stp = &SUG(*gap, 0);
     int                i;
 
-    // Sort the list.
-    qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
-
-    // Truncate the list to the number of suggestions that will be displayed.
-    if (gap->ga_len > keep)
+    if (gap->ga_len > 0)
     {
-       for (i = keep; i < gap->ga_len; ++i)
-           vim_free(stp[i].st_word);
-       gap->ga_len = keep;
-       if (keep >= 1)
-           return stp[keep - 1].st_score;
+       // Sort the list.
+       qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T),
+                                                                 sug_compare);
+
+       // Truncate the list to the number of suggestions that will be
+       // displayed.
+       if (gap->ga_len > keep)
+       {
+           for (i = keep; i < gap->ga_len; ++i)
+               vim_free(stp[i].st_word);
+           gap->ga_len = keep;
+           if (keep >= 1)
+               return stp[keep - 1].st_score;
+       }
     }
     return maxscore;
 }
index 7d2f12ede5fdc6451dfa284d94ff413b4a4695a9..a25685c0ffe988d329cfdbaa77b565372238846a 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    387,
 /**/
     386,
 /**/