aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/spell.c
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-03-15 14:50:36 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-04-13 12:00:30 -0400
commit351a1cff70a2e2294adb4a90ff35cea38c2accec (patch)
tree59ea9139a57202a34bc6511b352fc6c71cc5e981 /src/nvim/spell.c
parent35e798c3a71573d2204c8e21a28e0a4b882c54cb (diff)
downloadrneovim-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/nvim/spell.c')
-rw-r--r--src/nvim/spell.c19
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;
}