[librsvg] Replace g_new() with g_new0() throughout



commit 21720f56a7a960c10650a3ba3a983f2f305adb6d
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed May 17 21:16:41 2017 -0500

    Replace g_new() with g_new0() throughout
    
    We should not have uninitialized memory!  I'm not confident
    that we are actually initializing every struct field by hand.

 rsvg-base.c         |    2 +-
 rsvg-cairo-draw.c   |    2 +-
 rsvg-cairo-render.c |    3 ++-
 rsvg-css.c          |    4 ++--
 rsvg-defs.c         |    2 +-
 rsvg-filter.c       |   14 +++++++-------
 rsvg-mask.c         |    2 +-
 rsvg-paint-server.c |   10 +++++-----
 rsvg-styles.c       |   10 +++++-----
 9 files changed, 25 insertions(+), 24 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 114e8ec..1dfc6e2 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -2425,7 +2425,7 @@ rsvg_render_free (RsvgRender * render)
 void
 rsvg_drawing_ctx_push_view_box (RsvgDrawingCtx * ctx, double w, double h)
 {
-    RsvgViewBox *vb = g_new (RsvgViewBox, 1);
+    RsvgViewBox *vb = g_new0 (RsvgViewBox, 1);
     *vb = ctx->vb;
     ctx->vb_stack = g_slist_prepend (ctx->vb_stack, vb);
     ctx->vb.rect.width = w;
diff --git a/rsvg-cairo-draw.c b/rsvg-cairo-draw.c
index 831c1c5..6055220 100644
--- a/rsvg-cairo-draw.c
+++ b/rsvg-cairo-draw.c
@@ -809,7 +809,7 @@ rsvg_cairo_push_render_stack (RsvgDrawingCtx * ctx)
     render->cr_stack = g_list_prepend (render->cr_stack, render->cr);
     render->cr = child_cr;
 
-    bbox = g_new (RsvgBbox, 1);
+    bbox = g_new0 (RsvgBbox, 1);
     *bbox = render->bbox;
     render->bb_stack = g_list_prepend (render->bb_stack, bbox);
     rsvg_bbox_init (&render->bbox, &state->affine);
diff --git a/rsvg-cairo-render.c b/rsvg-cairo-render.c
index 22a319c..a708fe6 100644
--- a/rsvg-cairo-render.c
+++ b/rsvg-cairo-render.c
@@ -142,7 +142,7 @@ rsvg_cairo_new_drawing_ctx (cairo_t * cr, RsvgHandle * handle)
     if (data.width == 0 || data.height == 0)
         return NULL;
 
-    draw = g_new (RsvgDrawingCtx, 1);
+    draw = g_new0 (RsvgDrawingCtx, 1);
 
     cairo_get_matrix (cr, &affine);
 
@@ -170,6 +170,7 @@ rsvg_cairo_new_drawing_ctx (cairo_t * cr, RsvgHandle * handle)
     draw->vb.rect.width = data.em;
     draw->vb.rect.height = data.ex;
     draw->pango_context = NULL;
+    draw->vb_stack = NULL;
     draw->drawsub_stack = NULL;
     draw->acquired_nodes = NULL;
     draw->is_testing = handle->priv->is_testing;
diff --git a/rsvg-css.c b/rsvg-css.c
index 75338ab..71e07f9 100644
--- a/rsvg-css.c
+++ b/rsvg-css.c
@@ -473,7 +473,7 @@ rsvg_css_parse_list (const char *in_str, guint * out_list_len)
     if (string_list) {
         GSList *slist;
 
-        string_array = g_new (gchar *, n + 1);
+        string_array = g_new0 (gchar *, n + 1);
 
         string_array[n--] = NULL;
         for (slist = string_list; slist; slist = slist->next)
@@ -500,7 +500,7 @@ rsvg_css_parse_number_list (const char *in_str, guint * out_list_len)
     if (!(string_array && len))
         return NULL;
 
-    output = g_new (gdouble, len);
+    output = g_new0 (gdouble, len);
 
     /* TODO: some error checking */
     for (i = 0; i < len; i++)
diff --git a/rsvg-defs.c b/rsvg-defs.c
index 2eaaf63..7966612 100644
--- a/rsvg-defs.c
+++ b/rsvg-defs.c
@@ -40,7 +40,7 @@ struct _RsvgDefs {
 RsvgDefs *
 rsvg_defs_new (RsvgHandle *handle)
 {
-    RsvgDefs *result = g_new (RsvgDefs, 1);
+    RsvgDefs *result = g_new0 (RsvgDefs, 1);
 
     result->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) rsvg_node_unref);
     result->externs =
diff --git a/rsvg-filter.c b/rsvg-filter.c
index b517d72..906dae8 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -621,7 +621,7 @@ rsvg_filter_store_output (GString * name, RsvgFilterPrimitiveOutput result, Rsvg
 
     cairo_surface_destroy (ctx->lastresult.surface);
 
-    store = g_new (RsvgFilterPrimitiveOutput, 1);
+    store = g_new0 (RsvgFilterPrimitiveOutput, 1);
     *store = result;
 
     if (name->str[0] != '\0') {
@@ -1369,7 +1369,7 @@ box_blur_line (gint box_width, gint even_offset,
                       kernel; it's the pixel to remove from the accumulator. */
     gint  *ac;     /* Accumulator for each channel                           */
 
-    ac = g_new (gint, bpp);
+    ac = g_new0 (gint, bpp);
 
     /* The algorithm differs for even and odd-sized kernels.
      * With the output at the center,
@@ -1515,7 +1515,7 @@ make_gaussian_convolution_matrix (gdouble radius, gdouble **out_matrix, gint *ou
     if (matrix_len <= 0)
         matrix_len = 1;
 
-    matrix = g_new (gdouble, matrix_len);
+    matrix = g_new0 (gdouble, matrix_len);
 
     /* Fill the matrix by doing numerical integration approximation
      * from -2*std_dev to 2*std_dev, sampling 50 points per pixel.
@@ -1802,7 +1802,7 @@ gaussian_blur_surface (cairo_surface_t *in,
             box_width = compute_box_blur_width (sx);
 
             /* twice the size so we can have "two" scratch rows */
-            row_buffer = g_new (guchar, width * bpp * 2);
+            row_buffer = g_new0 (guchar, width * bpp * 2);
             row1 = row_buffer;
             row2 = row_buffer + width * bpp;
         } else
@@ -1854,7 +1854,7 @@ gaussian_blur_surface (cairo_surface_t *in,
         int x;
 
         /* twice the size so we can have the source pixels and the blurred pixels */
-        col_buffer = g_new (guchar, height * bpp * 2);
+        col_buffer = g_new0 (guchar, height * bpp * 2);
         col1 = col_buffer;
         col2 = col_buffer + height * bpp;
 
@@ -2377,7 +2377,7 @@ rsvg_filter_primitive_color_matrix_set_atts (RsvgNode *node, gpointer impl, Rsvg
     if ((value = rsvg_property_bag_lookup (atts, "values"))) {
         unsigned int i;
         double *temp = rsvg_css_parse_number_list (value, &listlen);
-        filter->KernelMatrix = g_new (int, listlen);
+        filter->KernelMatrix = g_new0 (int, listlen);
         for (i = 0; i < listlen; i++)
             filter->KernelMatrix[i] = temp[i] * 255.;
         g_free (temp);
@@ -2739,7 +2739,7 @@ rsvg_node_component_transfer_function_set_atts (RsvgNode *node, gpointer impl, R
         unsigned int i;
         double *temp = rsvg_css_parse_number_list (value,
                                                    &data->nbTableValues);
-        data->tableValues = g_new (gint, data->nbTableValues);
+        data->tableValues = g_new0 (gint, data->nbTableValues);
         for (i = 0; i < data->nbTableValues; i++)
             data->tableValues[i] = temp[i] * 255.;
         g_free (temp);
diff --git a/rsvg-mask.c b/rsvg-mask.c
index 218e459..212d782 100644
--- a/rsvg-mask.c
+++ b/rsvg-mask.c
@@ -110,7 +110,7 @@ rsvg_new_clip_path (const char *element_name, RsvgNode *parent)
 {
     RsvgClipPath *clip_path;
 
-    clip_path = g_new (RsvgClipPath, 1);
+    clip_path = g_new0 (RsvgClipPath, 1);
     clip_path->units = userSpaceOnUse;
 
     return rsvg_rust_cnode_new (RSVG_NODE_TYPE_CLIP_PATH,
diff --git a/rsvg-paint-server.c b/rsvg-paint-server.c
index 785f97c..009aed6 100644
--- a/rsvg-paint-server.c
+++ b/rsvg-paint-server.c
@@ -39,11 +39,11 @@
 static RsvgPaintServer *
 rsvg_paint_server_solid (guint32 argb)
 {
-    RsvgPaintServer *result = g_new (RsvgPaintServer, 1);
+    RsvgPaintServer *result = g_new0 (RsvgPaintServer, 1);
 
     result->refcnt = 1;
     result->type = RSVG_PAINT_SERVER_SOLID;
-    result->core.color = g_new (RsvgSolidColor, 1);
+    result->core.color = g_new0 (RsvgSolidColor, 1);
     result->core.color->argb = argb;
     result->core.color->currentcolor = FALSE;
 
@@ -53,11 +53,11 @@ rsvg_paint_server_solid (guint32 argb)
 static RsvgPaintServer *
 rsvg_paint_server_solid_current_color (void)
 {
-    RsvgPaintServer *result = g_new (RsvgPaintServer, 1);
+    RsvgPaintServer *result = g_new0 (RsvgPaintServer, 1);
 
     result->refcnt = 1;
     result->type = RSVG_PAINT_SERVER_SOLID;
-    result->core.color = g_new (RsvgSolidColor, 1);
+    result->core.color = g_new0 (RsvgSolidColor, 1);
     result->core.color->currentcolor = TRUE;
 
     return result;
@@ -66,7 +66,7 @@ rsvg_paint_server_solid_current_color (void)
 static RsvgPaintServer *
 rsvg_paint_server_iri (char *iri, gboolean has_alternate, RsvgSolidColor alternate)
 {
-    RsvgPaintServer *result = g_new (RsvgPaintServer, 1);
+    RsvgPaintServer *result = g_new0 (RsvgPaintServer, 1);
 
     result->refcnt = 1;
     result->type = RSVG_PAINT_SERVER_IRI;
diff --git a/rsvg-styles.c b/rsvg-styles.c
index ef32d63..74d42f1 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -66,7 +66,7 @@ style_value_data_new (const gchar *value, gboolean important)
 {
     StyleValueData *ret;
 
-    ret = g_new (StyleValueData, 1);
+    ret = g_new0 (StyleValueData, 1);
     ret->value = g_strdup (value);
     ret->important = important;
 
@@ -282,7 +282,7 @@ rsvg_state_clone (RsvgState * dst, const RsvgState * src)
     dst->styles = g_hash_table_ref (src->styles);
 
     if (src->dash.n_dash > 0) {
-        dst->dash.dash = g_new (gdouble, src->dash.n_dash);
+        dst->dash.dash = g_new0 (gdouble, src->dash.n_dash);
         for (i = 0; i < src->dash.n_dash; i++)
             dst->dash.dash[i] = src->dash.dash[i];
     }
@@ -409,7 +409,7 @@ rsvg_state_inherit_run (RsvgState * dst, const RsvgState * src,
         if (dst->has_dash)
             g_free (dst->dash.dash);
 
-        dst->dash.dash = g_new (gdouble, src->dash.n_dash);
+        dst->dash.dash = g_new0 (gdouble, src->dash.n_dash);
         dst->dash.n_dash = src->dash.n_dash;
         for (i = 0; i < src->dash.n_dash; i++)
             dst->dash.dash[i] = src->dash.dash[i];
@@ -897,7 +897,7 @@ rsvg_parse_style_pair (RsvgState * state,
 
                 is_even = (n_dashes % 2 == 0);
                 state->dash.n_dash = (is_even ? n_dashes : n_dashes * 2);
-                state->dash.dash = g_new (double, state->dash.n_dash);
+                state->dash.dash = g_new0 (double, state->dash.n_dash);
 
                 /* TODO: handle negative value == error case */
 
@@ -1328,7 +1328,7 @@ rsvg_lookup_apply_css_style (RsvgHandle * ctx, const char *target, RsvgState * s
     styles = g_hash_table_lookup (ctx->priv->css_props, target);
 
     if (styles != NULL) {
-        StylesData *data = g_new (StylesData, 1);
+        StylesData *data = g_new0 (StylesData, 1);
         data->ctx = ctx;
         data->state = state;
         g_hash_table_foreach (styles, (GHFunc) apply_style, data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]