From 29e9cea1dd68da695217c82c15bfd039b46f7729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 9 Feb 2019 10:58:26 +0100 Subject: [PATCH] decorations: 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. --- decorations/background.c | 4 ++-- decorations/stack.c | 4 ++-- decorations/underline.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/decorations/background.c b/decorations/background.c index 992bdf2..ef7b12b 100644 --- a/decorations/background.c +++ b/decorations/background.c @@ -30,10 +30,10 @@ expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height static struct deco * background_new(struct rgba color) { - struct private *priv = malloc(sizeof(*priv)); + struct private *priv = calloc(1, sizeof(*priv)); priv->color = color; - struct deco *deco = malloc(sizeof(*deco)); + struct deco *deco = calloc(1, sizeof(*deco)); deco->private = priv; deco->expose = &expose; deco->destroy = &destroy; diff --git a/decorations/stack.c b/decorations/stack.c index a5662b0..3ffaab5 100644 --- a/decorations/stack.c +++ b/decorations/stack.c @@ -34,14 +34,14 @@ expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height static struct deco * stack_new(struct deco *decos[], size_t count) { - struct private *priv = malloc(sizeof(*priv)); + struct private *priv = calloc(1, sizeof(*priv)); priv->decos = malloc(count * sizeof(priv->decos[0])); priv->count = count; for (size_t i = 0; i < count; i++) priv->decos[i] = decos[i]; - struct deco *deco = malloc(sizeof(*deco)); + struct deco *deco = calloc(1, sizeof(*deco)); deco->private = priv; deco->expose = &expose; deco->destroy = &destroy; diff --git a/decorations/underline.c b/decorations/underline.c index 9c71efe..996d54a 100644 --- a/decorations/underline.c +++ b/decorations/underline.c @@ -31,11 +31,11 @@ expose(const struct deco *deco, cairo_t *cr, int x, int y, int width, int height static struct deco * underline_new(int size, struct rgba color) { - struct private *priv = malloc(sizeof(*priv)); + struct private *priv = calloc(1, sizeof(*priv)); priv->size = size; priv->color = color; - struct deco *deco = malloc(sizeof(*deco)); + struct deco *deco = calloc(1, sizeof(*deco)); deco->private = priv; deco->expose = &expose; deco->destroy = &destroy;