diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-03-15 18:15:03 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-03-15 18:15:03 +0100 |
commit | bb65a5690c24ccfce37e210316bf1d0964c91359 (patch) | |
tree | 2e42a98f5924a20f29bbc45bed10f6e2ccfcee0b | |
parent | 0bdbc10e8a74e7dd447cd975fb1445bbdcbb4f37 (diff) | |
download | vim-git-bb65a5690c24ccfce37e210316bf1d0964c91359.tar.gz |
patch 8.2.0387: error for possible NULL argument to qsort()v8.2.0387
Problem: Error for possible NULL argument to qsort().
Solution: Don't call qsort() when there is nothing to sort. (Dominique
Pelle, closes #5780)
-rw-r--r-- | src/spellsuggest.c | 25 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/spellsuggest.c b/src/spellsuggest.c index fdd549e47..267a4a58c 100644 --- a/src/spellsuggest.c +++ b/src/spellsuggest.c @@ -3719,17 +3719,22 @@ cleanup_suggestions( suggest_T *stp = &SUG(*gap, 0); int i; - // 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) + if (gap->ga_len > 0) { - for (i = keep; i < gap->ga_len; ++i) - vim_free(stp[i].st_word); - gap->ga_len = keep; - if (keep >= 1) - return stp[keep - 1].st_score; + // 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 (i = keep; i < gap->ga_len; ++i) + vim_free(stp[i].st_word); + gap->ga_len = keep; + if (keep >= 1) + return stp[keep - 1].st_score; + } } return maxscore; } diff --git a/src/version.c b/src/version.c index 7d2f12ede..a25685c0f 100644 --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 387, +/**/ 386, /**/ 385, |