forked from external/yambar
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.
This commit is contained in:
parent
83591b9269
commit
29e9cea1dd
3 changed files with 6 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue