#endif
static int binsearch(
- void **dst, const void *x, size_t size, git__tsort_r_cmp cmp, void *payload)
+ void **dst, const void *x, size_t size, git__sort_r_cmp cmp, void *payload)
{
int l, c, r;
void *lx, *cx;
- assert(size > 0);
-
l = 0;
r = (int)size - 1;
c = r >> 1;
/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */
static void bisort(
- void **dst, size_t start, size_t size, git__tsort_r_cmp cmp, void *payload)
+ void **dst, size_t start, size_t size, git__sort_r_cmp cmp, void *payload)
{
size_t i;
void *x;
struct tsort_store {
size_t alloc;
- git__tsort_r_cmp cmp;
+ git__sort_r_cmp cmp;
void *payload;
void **storage;
};
static int resize(struct tsort_store *store, size_t new_size)
{
if (store->alloc < new_size) {
- void **tempstore = git__realloc(store->storage, new_size * sizeof(void *));
+ void **tempstore;
+
+ tempstore = git__reallocarray(store->storage, new_size, sizeof(void *));
/**
* Do not propagate on OOM; this will abort the sort and
#define PUSH_NEXT() do {\
len = count_run(dst, curr, size, store);\
run = minrun;\
- if (run < minrun) run = minrun;\
if (run > (ssize_t)size - curr) run = size - curr;\
if (run > len) {\
bisort(&dst[curr], len, run, cmp, payload);\
while (0)
void git__tsort_r(
- void **dst, size_t size, git__tsort_r_cmp cmp, void *payload)
+ void **dst, size_t size, git__sort_r_cmp cmp, void *payload)
{
struct tsort_store _store, *store = &_store;
struct tsort_run run_stack[128];