vim-patch:8.2.0387: error for possible NULL argument to qsort()

Problem:    Error for possible NULL argument to qsort().
Solution:   Don't call qsort() when there is nothing to sort. (Dominique
            Pelle, closes vim/vim#5780)
bb65a5690c
This commit is contained in:
Jan Edmund Lazo
2020-03-15 14:50:36 -04:00
parent 35e798c3a7
commit 351a1cff70

View File

@@ -5761,19 +5761,22 @@ cleanup_suggestions (
int maxscore,
int keep // nr of suggestions to keep
)
FUNC_ATTR_NONNULL_ALL
{
suggest_T *stp = &SUG(*gap, 0);
// Sort the list.
qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
if (gap->ga_len > 0) {
// 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 (int i = keep; i < gap->ga_len; ++i) {
xfree(stp[i].st_word);
// Truncate the list to the number of suggestions that will be displayed.
if (gap->ga_len > keep) {
for (int i = keep; i < gap->ga_len; i++) {
xfree(stp[i].st_word);
}
gap->ga_len = keep;
return stp[keep - 1].st_score;
}
gap->ga_len = keep;
return stp[keep - 1].st_score;
}
return maxscore;
}