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:
Daniel Eklöf 2019-02-09 11:05:12 +01:00
parent 29e9cea1dd
commit 6bba9200cf
7 changed files with 16 additions and 23 deletions

View file

@ -28,7 +28,7 @@ particle_common_new(int left_margin, int right_margin,
struct font *font, struct rgba foreground,
struct deco *deco)
{
struct particle *p = malloc(sizeof(*p));
struct particle *p = calloc(1, sizeof(*p));
p->left_margin = left_margin;
p->right_margin = right_margin;
p->on_click_template =
@ -120,14 +120,10 @@ exposable_default_on_mouse(struct exposable *exposable, struct bar *bar,
struct exposable *
exposable_common_new(const struct particle *particle, const char *on_click)
{
struct exposable *exposable = malloc(sizeof(*exposable));
struct exposable *exposable = calloc(1, sizeof(*exposable));
exposable->particle = particle;
exposable->private = NULL;
exposable->width = 0;
exposable->on_click = on_click != NULL ? strdup(on_click) : NULL;
exposable->destroy = &exposable_default_destroy;
exposable->on_mouse = &exposable_default_on_mouse;
exposable->begin_expose = NULL;
exposable->expose = NULL;
return exposable;
}