From 351a1cff70a2e2294adb4a90ff35cea38c2accec Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 15 Mar 2020 14:50:36 -0400 Subject: 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) https://github.com/vim/vim/commit/bb65a5690c24ccfce37e210316bf1d0964c91359 --- src/nvim/spell.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 6cb8d01f51..545a381bd3 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -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; } -- cgit