Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't pass NULL to qsort() #297

Merged
merged 2 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion kvlds/btree_mutate.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@ btree_mutate_immutable(struct node * N)
if (N->v.H->pairs[i].v != NULL)
nkeys_hash += 1;

/* Allocate new array of key-value pairs. */
/* How many key-value pairs do we have? */
new_nkeys = nkeys_list + nkeys_hash;

/* If there's nothing to do, do nothing. */
if (new_nkeys == 0) {
new_pairs = NULL;
goto done;
}

/* Allocate new array of key-value pairs. */
if (IMALLOC(new_pairs, new_nkeys, struct kvpair_const))
goto err0;

Expand Down Expand Up @@ -151,6 +159,7 @@ btree_mutate_immutable(struct node * N)
j++;
}

done:
/* Free old array of key-value pairs. */
free(N->u.pairs);

Expand Down
4 changes: 4 additions & 0 deletions lib/datastruct/kvpair.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <assert.h>
#include <stdlib.h>

#include "kvldskey.h"
Expand Down Expand Up @@ -45,6 +46,9 @@ void
kvpair_sort(struct kvpair * pairs, size_t npairs, size_t mlen)
{

/* Sanity check. */
assert(pairs != NULL);

/* See above comments about cookie_mlen and non-threadsafety. */
cookie_mlen = mlen;

Expand Down
Loading