forked from external/yambar
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
|
@ -120,7 +120,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
|||
|
||||
struct particle *pp = p->particles[idx];
|
||||
|
||||
struct eprivate *e = malloc(sizeof(*e));
|
||||
struct eprivate *e = calloc(1, sizeof(*e));
|
||||
e->exposable = pp->instantiate(pp, tags);
|
||||
|
||||
char *on_click = tags_expand_template(particle->on_click_template, tags);
|
||||
|
@ -140,9 +140,9 @@ ramp_new(struct particle *common, const char *tag,
|
|||
struct particle *particles[], size_t count)
|
||||
{
|
||||
|
||||
struct private *priv = malloc(sizeof(*priv));
|
||||
struct private *priv = calloc(1, sizeof(*priv));
|
||||
priv->tag = strdup(tag);
|
||||
priv->particles = calloc(count, sizeof(priv->particles[0]));
|
||||
priv->particles = malloc(count * sizeof(priv->particles[0]));
|
||||
priv->count = count;
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue