Skip to content

Commit

Permalink
[DCT-4]: Swap to ddsrt_malloc_s in hopscotch
Browse files Browse the repository at this point in the history
  • Loading branch information
noxpardalis committed Aug 21, 2023
1 parent 1d7ef26 commit 739da84
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ddsrt/src/hopscotch.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static bool ddsrt_chh_data_valid_p (void *data)
return data != NULL && data != CHH_BUSY;
}

static int ddsrt_chh_init (struct ddsrt_chh *rt, uint32_t init_size, ddsrt_hh_hash_fn hash, ddsrt_hh_equals_fn equals, ddsrt_hh_buckets_gc_fn gc_buckets, void *gc_buckets_arg)
static dds_return_t ddsrt_chh_init (struct ddsrt_chh *rt, uint32_t init_size, ddsrt_hh_hash_fn hash, ddsrt_hh_equals_fn equals, ddsrt_hh_buckets_gc_fn gc_buckets, void *gc_buckets_arg)
{
uint32_t size;
uint32_t i;
Expand All @@ -328,7 +328,10 @@ static int ddsrt_chh_init (struct ddsrt_chh *rt, uint32_t init_size, ddsrt_hh_ha
rt->gc_buckets = gc_buckets;
rt->gc_buckets_arg = gc_buckets_arg;

buckets = ddsrt_malloc (offsetof (struct ddsrt_chh_bucket_array, bs) + size * sizeof (*buckets->bs));
buckets = ddsrt_malloc_s (offsetof (struct ddsrt_chh_bucket_array, bs) + size * sizeof (*buckets->bs));
if (buckets == NULL) {
return DDS_RETCODE_OUT_OF_RESOURCES;
}
ddsrt_atomic_stvoidp (&rt->buckets, buckets);
buckets->size = size;
for (i = 0; i < size; i++) {
Expand All @@ -338,7 +341,7 @@ static int ddsrt_chh_init (struct ddsrt_chh *rt, uint32_t init_size, ddsrt_hh_ha
ddsrt_atomic_stvoidp (&b->data, NULL);
}
ddsrt_mutex_init (&rt->change_lock);
return 0;
return DDS_RETCODE_OK;
}

static void ddsrt_chh_fini (struct ddsrt_chh *rt)
Expand All @@ -349,8 +352,8 @@ static void ddsrt_chh_fini (struct ddsrt_chh *rt)

struct ddsrt_chh *ddsrt_chh_new (uint32_t init_size, ddsrt_hh_hash_fn hash, ddsrt_hh_equals_fn equals, ddsrt_hh_buckets_gc_fn gc_buckets, void *gc_buckets_arg)
{
struct ddsrt_chh *hh = ddsrt_malloc (sizeof (*hh));
if (ddsrt_chh_init (hh, init_size, hash, equals, gc_buckets, gc_buckets_arg) < 0) {
struct ddsrt_chh *hh = ddsrt_malloc_s (sizeof (*hh));
if (hh == NULL || ddsrt_chh_init (hh, init_size, hash, equals, gc_buckets, gc_buckets_arg) < 0) {
ddsrt_free (hh);
return NULL;
} else {
Expand Down

0 comments on commit 739da84

Please sign in to comment.