Skip to content

Commit

Permalink
No need for calloc here.
Browse files Browse the repository at this point in the history
  • Loading branch information
katef committed Aug 25, 2024
1 parent 6a40553 commit f1ca8e8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/adt/edgeset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/adt/idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions src/adt/internedstateset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand All @@ -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,
Expand All @@ -108,7 +108,7 @@ interned_state_set_pool_alloc(const struct fsm_alloc *a)
.buckets = buckets,
},
};
memcpy(res, &p, sizeof(p));

return res;

cleanup:
Expand Down
4 changes: 3 additions & 1 deletion src/adt/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 7 additions & 2 deletions src/libfsm/capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion src/libfsm/endids.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f1ca8e8

Please sign in to comment.