From f1ca8e8c679f57b3877f4e2392891fa791c5a58e Mon Sep 17 00:00:00 2001 From: Kate F Date: Sun, 25 Aug 2024 20:36:33 +0100 Subject: [PATCH] No need for calloc here. --- src/adt/edgeset.c | 4 ++-- src/adt/idmap.c | 1 + src/adt/internedstateset.c | 6 +++--- src/adt/queue.c | 4 +++- src/libfsm/capture.c | 9 +++++++-- src/libfsm/endids.c | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/adt/edgeset.c b/src/adt/edgeset.c index 8e2554c33..178ddbc2b 100644 --- a/src/adt/edgeset.c +++ b/src/adt/edgeset.c @@ -121,7 +121,7 @@ dump_edge_set(const struct edge_set *set) static struct edge_set * init_empty(const struct fsm_alloc *alloc) { - struct edge_set *set = f_calloc(alloc, 1, sizeof(*set)); + struct edge_set *set = f_malloc(alloc, sizeof(*set)); if (set == NULL) { return NULL; } @@ -719,7 +719,7 @@ edge_set_copy(struct edge_set **dst, const struct fsm_alloc *alloc, return 1; } - set = f_calloc(alloc, 1, sizeof(*set)); + set = f_malloc(alloc, sizeof(*set)); if (set == NULL) { return 0; } diff --git a/src/adt/idmap.c b/src/adt/idmap.c index 208af3c5a..e3facfa49 100644 --- a/src/adt/idmap.c +++ b/src/adt/idmap.c @@ -119,6 +119,7 @@ grow_bucket_values(struct idmap *m, unsigned old_words, unsigned new_words) return 0; } + // TODO: memcpy for (size_t w_i = 0; w_i < old_words; w_i++) { nv[w_i] = b->values[w_i]; } diff --git a/src/adt/internedstateset.c b/src/adt/internedstateset.c index 9daf50ae7..990d9c98f 100644 --- a/src/adt/internedstateset.c +++ b/src/adt/internedstateset.c @@ -77,7 +77,7 @@ interned_state_set_pool_alloc(const struct fsm_alloc *a) fsm_state_t *buf = NULL; uint32_t *buckets = NULL; - res = f_calloc(a, 1, sizeof(*res)); + res = f_malloc(a, sizeof(*res)); if (res == NULL) { goto cleanup; } sets = f_malloc(a, DEF_SETS * sizeof(sets[0])); @@ -93,7 +93,7 @@ interned_state_set_pool_alloc(const struct fsm_alloc *a) buckets[i] = NO_ID; } - struct interned_state_set_pool p = { + *res = (struct interned_state_set_pool) { .alloc = a, .sets = { .ceil = DEF_SETS, @@ -108,7 +108,7 @@ interned_state_set_pool_alloc(const struct fsm_alloc *a) .buckets = buckets, }, }; - memcpy(res, &p, sizeof(p)); + return res; cleanup: diff --git a/src/adt/queue.c b/src/adt/queue.c index 1e5d28e08..9f3507f69 100644 --- a/src/adt/queue.c +++ b/src/adt/queue.c @@ -30,11 +30,13 @@ queue_new(const struct fsm_alloc *a, size_t max_capacity) if (max_capacity == 0) { return NULL; } alloc_size = sizeof(*q) + (max_capacity - 1) * sizeof(q->q[0]); - q = f_calloc(a, 1, alloc_size); + q = f_malloc(a, alloc_size); if (q == NULL) { return NULL; } q->alloc = a; q->capacity = max_capacity; + q->rd = 0; + q->wr = 0; return q; } diff --git a/src/libfsm/capture.c b/src/libfsm/capture.c index 3f750169e..d928a7b77 100644 --- a/src/libfsm/capture.c +++ b/src/libfsm/capture.c @@ -14,11 +14,16 @@ fsm_capture_init(struct fsm *fsm) struct fsm_capture_info *ci = NULL; size_t i; - ci = f_calloc(fsm->alloc, - 1, sizeof(*ci)); + ci = f_malloc(fsm->alloc, sizeof(*ci)); if (ci == NULL) { goto cleanup; } + + ci->max_capture_id = 0; + ci->bucket_count = 0; + ci->buckets_used = 0; + ci->buckets = NULL; + fsm->capture_info = ci; for (i = 0; i < fsm->statealloc; i++) { diff --git a/src/libfsm/endids.c b/src/libfsm/endids.c index f77905f67..d889d057b 100644 --- a/src/libfsm/endids.c +++ b/src/libfsm/endids.c @@ -89,7 +89,7 @@ fsm_endid_init(struct fsm *fsm) { struct endid_info_bucket *buckets = NULL; size_t i; - struct endid_info *res = f_calloc(fsm->alloc, 1, sizeof(*res)); + struct endid_info *res = f_malloc(fsm->alloc, sizeof(*res)); if (res == NULL) { return 0; }