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

@ -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;