Skip to content

Commit

Permalink
qsort may deref NULL pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbra committed Jul 18, 2024
1 parent 5ad0199 commit 0a631cb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/insexpand.c
Original file line number Diff line number Diff line change
Expand Up @@ -3588,12 +3588,16 @@ get_next_filename_completion(void)
}
}

fuzzy_indices_data = (int *)fuzzy_indices.ga_data;
qsort(fuzzy_indices_data, fuzzy_indices.ga_len, sizeof(int), compare_scores);
// prevent qsort from deref NULL pointer
if (fuzzy_indices.ga_len > 0)
{
fuzzy_indices_data = (int *)fuzzy_indices.ga_data;
qsort(fuzzy_indices_data, fuzzy_indices.ga_len, sizeof(int), compare_scores);

sorted_matches = (char_u **)alloc(sizeof(char_u *) * fuzzy_indices.ga_len);
for (i = 0; i < fuzzy_indices.ga_len; ++i)
sorted_matches[i] = vim_strsave(matches[fuzzy_indices_data[i]]);
sorted_matches = (char_u **)alloc(sizeof(char_u *) * fuzzy_indices.ga_len);
for (i = 0; i < fuzzy_indices.ga_len; ++i)
sorted_matches[i] = vim_strsave(matches[fuzzy_indices_data[i]]);
}

FreeWild(num_matches, matches);
matches = sorted_matches;
Expand Down

0 comments on commit 0a631cb

Please sign in to comment.