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

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