diff --git a/particle.c b/particle.c index dfca044..5f605ea 100644 --- a/particle.c +++ b/particle.c @@ -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; } diff --git a/particles/dynlist.c b/particles/dynlist.c index ed656fc..e6a3636 100644 --- a/particles/dynlist.c +++ b/particles/dynlist.c @@ -98,10 +98,10 @@ struct exposable * dynlist_exposable_new(struct exposable **exposables, size_t count, int left_spacing, int right_spacing) { - struct private *e = malloc(sizeof(*e)); + struct private *e = calloc(1, sizeof(*e)); e->count = count; e->exposables = malloc(count * sizeof(e->exposables[0])); - e->widths = malloc(count * sizeof(e->widths[0])); + e->widths = calloc(count, sizeof(e->widths[0])); e->left_spacing = left_spacing; e->right_spacing = right_spacing; diff --git a/particles/list.c b/particles/list.c index 68b7186..a47c468 100644 --- a/particles/list.c +++ b/particles/list.c @@ -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; diff --git a/particles/map.c b/particles/map.c index 5acc7f9..a8895cb 100644 --- a/particles/map.c +++ b/particles/map.c @@ -111,7 +111,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags) pp = p->default_particle; } - 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); @@ -151,7 +151,7 @@ map_new(struct particle *common, const char *tag, const struct particle_map particle_map[], size_t count, struct particle *default_particle) { - struct private *priv = malloc(sizeof(*priv)); + struct private *priv = calloc(1, sizeof(*priv)); priv->tag = strdup(tag); priv->default_particle = default_particle; priv->count = count; diff --git a/particles/progress-bar.c b/particles/progress-bar.c index a10f9e2..762178e 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -144,7 +144,7 @@ instantiate(const struct particle *particle, const struct tag_set *tags) long fill_count = max == min ? 0 : p->width * value / (max - min); long empty_count = p->width - fill_count; - struct eprivate *epriv = malloc(sizeof(*epriv)); + struct eprivate *epriv = calloc(1, sizeof(*epriv)); epriv->count = ( 1 + /* Start marker */ fill_count + /* Before current position */ @@ -214,7 +214,7 @@ progress_bar_new(struct particle *common, const char *tag, int width, struct particle *fill, struct particle *empty, struct particle *indicator) { - struct private *priv = malloc(sizeof(*priv)); + struct private *priv = calloc(1, sizeof(*priv)); priv->tag = strdup(tag); priv->width = width; priv->start_marker = start_marker; diff --git a/particles/ramp.c b/particles/ramp.c index a9cf627..1f8ef11 100644 --- a/particles/ramp.c +++ b/particles/ramp.c @@ -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++) diff --git a/particles/string.c b/particles/string.c index 5c06378..58e1984 100644 --- a/particles/string.c +++ b/particles/string.c @@ -108,12 +108,9 @@ static struct exposable * 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->text = tags_expand_template(p->text, tags); - memset(&e->extents, 0, sizeof(e->extents)); - e->glyphs = NULL; - e->clusters = NULL; e->num_glyphs = -1; e->num_clusters = -1; @@ -164,7 +161,7 @@ particle_destroy(struct particle *particle) static struct particle * string_new(struct particle *common, const char *text, size_t max_len) { - struct private *p = malloc(sizeof(*p)); + struct private *p = calloc(1, sizeof(*p)); p->text = strdup(text); p->max_len = max_len;