mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-06-16 08:15:40 +02:00
particles: use calloc() instead of malloc()
In cases where it makes sense, use calloc() instead of malloc(): * When allocating large objects with many members, many for which NULL/0 is a good default value. * Arrays etc where we explicitly initialize to NULL anyway.
This commit is contained in:
parent
29e9cea1dd
commit
6bba9200cf
7 changed files with 16 additions and 23 deletions
|
@ -108,9 +108,9 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
|||
{
|
||||
const struct private *p = particle->private;
|
||||
|
||||
struct eprivate *e = malloc(sizeof(*e));
|
||||
struct eprivate *e = calloc(1, sizeof(*e));
|
||||
e->exposables = malloc(p->count * sizeof(*e->exposables));
|
||||
e->widths = malloc(p->count * sizeof(*e->widths));
|
||||
e->widths = calloc(p->count, sizeof(*e->widths));
|
||||
e->count = p->count;
|
||||
e->left_spacing = p->left_spacing;
|
||||
e->right_spacing = p->right_spacing;
|
||||
|
@ -149,7 +149,7 @@ particle_list_new(struct particle *common,
|
|||
struct particle *particles[], size_t count,
|
||||
int left_spacing, int right_spacing)
|
||||
{
|
||||
struct private *p = malloc(sizeof(*p));
|
||||
struct private *p = calloc(1, sizeof(*p));
|
||||
p->particles = malloc(count * sizeof(p->particles[0]));
|
||||
p->count = count;
|
||||
p->left_spacing = left_spacing;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue