comparison src/spellsuggest.c @ 19661:31d303c0c464 v8.2.0387

patch 8.2.0387: error for possible NULL argument to qsort() Commit: https://github.com/vim/vim/commit/bb65a5690c24ccfce37e210316bf1d0964c91359 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 15 18:15:03 2020 +0100 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 #5780)
author Bram Moolenaar <Bram@vim.org>
date Sun, 15 Mar 2020 18:30:04 +0100
parents 34aa888bf5ad
children 435726a03481
comparison
equal deleted inserted replaced
19660:738922dcb500 19661:31d303c0c464
3717 int keep) // nr of suggestions to keep 3717 int keep) // nr of suggestions to keep
3718 { 3718 {
3719 suggest_T *stp = &SUG(*gap, 0); 3719 suggest_T *stp = &SUG(*gap, 0);
3720 int i; 3720 int i;
3721 3721
3722 // Sort the list. 3722 if (gap->ga_len > 0)
3723 qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare); 3723 {
3724 3724 // Sort the list.
3725 // Truncate the list to the number of suggestions that will be displayed. 3725 qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T),
3726 if (gap->ga_len > keep) 3726 sug_compare);
3727 { 3727
3728 for (i = keep; i < gap->ga_len; ++i) 3728 // Truncate the list to the number of suggestions that will be
3729 vim_free(stp[i].st_word); 3729 // displayed.
3730 gap->ga_len = keep; 3730 if (gap->ga_len > keep)
3731 if (keep >= 1) 3731 {
3732 return stp[keep - 1].st_score; 3732 for (i = keep; i < gap->ga_len; ++i)
3733 vim_free(stp[i].st_word);
3734 gap->ga_len = keep;
3735 if (keep >= 1)
3736 return stp[keep - 1].st_score;
3737 }
3733 } 3738 }
3734 return maxscore; 3739 return maxscore;
3735 } 3740 }
3736 3741
3737 /* 3742 /*