diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-03-15 14:50:36 -0400 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-04-13 12:00:30 -0400 |
commit | 351a1cff70a2e2294adb4a90ff35cea38c2accec (patch) | |
tree | 59ea9139a57202a34bc6511b352fc6c71cc5e981 /src | |
parent | 35e798c3a71573d2204c8e21a28e0a4b882c54cb (diff) | |
download | rneovim-351a1cff70a2e2294adb4a90ff35cea38c2accec.tar.gz rneovim-351a1cff70a2e2294adb4a90ff35cea38c2accec.tar.bz2 rneovim-351a1cff70a2e2294adb4a90ff35cea38c2accec.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/spell.c | 19 |
1 files changed, 11 insertions, 8 deletions
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; } |