gtk: Move from g_memdup() to g_memdup2()
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 4 Feb 2021 19:18:28 +0000 (19:18 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Thu, 11 Feb 2021 14:22:22 +0000 (14:22 +0000)
The g_memdup() function is replaced by a safer version in newer versions
of GLib.

gtk/gtkbuilderparser.c
gtk/gtkcsskeyframes.c
gtk/gtkcssnodedeclaration.c
gtk/gtkexpression.c
gtk/gtkrange.c
gtk/gtkroundedbox.c
gtk/gtktreednd.c
modules/printbackends/gtkprintbackendcups.c

index b368d82cc5503da6922d45dd5f6a22502e3268a8..ba409bb22ccca9a35d72e6e0affb063ad57b3644 100644 (file)
@@ -28,6 +28,9 @@
 #include "gtkversion.h"
 #include "gdkprofilerprivate.h"
 
+/* XXX: For g_memdup2() */
+#include "gtkprivate.h"
+
 #include <gio/gio.h>
 #include <string.h>
 
@@ -1610,7 +1613,7 @@ create_subparser (GObject       *object,
   subparser->child = child;
   subparser->tagname = g_strdup (element_name);
   subparser->start = element_name;
-  subparser->parser = g_memdup (parser, sizeof (GtkBuildableParser));
+  subparser->parser = g_memdup2 (parser, sizeof (GtkBuildableParser));
   subparser->data = user_data;
 
   return subparser;
index e4a577379d81241830585a6e6626ff7f96f87d2f..f66178cae41d951aad7a857b488a541c1fcb63da 100644 (file)
@@ -24,6 +24,9 @@
 #include "gtkcssstylepropertyprivate.h"
 #include "gtkstylepropertyprivate.h"
 
+/* XXX: For g_memdup2() */
+#include "gtkprivate.h"
+
 #include <stdlib.h>
 #include <string.h>
 
@@ -441,9 +444,9 @@ _gtk_css_keyframes_compute (GtkCssKeyframes  *keyframes,
 
   resolved = gtk_css_keyframes_alloc ();
   resolved->n_keyframes = keyframes->n_keyframes;
-  resolved->keyframe_progress = g_memdup (keyframes->keyframe_progress, keyframes->n_keyframes * sizeof (double));
+  resolved->keyframe_progress = g_memdup2 (keyframes->keyframe_progress, keyframes->n_keyframes * sizeof (double));
   resolved->n_properties = keyframes->n_properties;
-  resolved->property_ids = g_memdup (keyframes->property_ids, keyframes->n_properties * sizeof (guint));
+  resolved->property_ids = g_memdup2 (keyframes->property_ids, keyframes->n_properties * sizeof (guint));
   resolved->values = g_new0 (GtkCssValue *, resolved->n_keyframes * resolved->n_properties);
 
   for (p = 0; p < resolved->n_properties; p++)
index ae78cf74ce9d10ccd1927cb4f59aa3efaf571e9c..73d002a3faeae8bd998d18ae3a66307477849a32 100644 (file)
@@ -19,6 +19,9 @@
 
 #include "gtkcssnodedeclarationprivate.h"
 
+/* XXX: For g_memdup2() */
+#include "gtkprivate.h"
+
 #include <string.h>
 
 struct _GtkCssNodeDeclaration {
@@ -51,7 +54,7 @@ gtk_css_node_declaration_make_writable (GtkCssNodeDeclaration **decl)
 
   (*decl)->refcount--;
 
-  *decl = g_memdup (*decl, sizeof_this_node (*decl));
+  *decl = g_memdup2 (*decl, sizeof_this_node (*decl));
   (*decl)->refcount = 1;
 }
 
index b08c8bf80f26ad6f1a8e3b61559bc81144a14d8c..7c3b016e1eb3119fe7ff1ccf28073af9670e3047 100644 (file)
@@ -22,6 +22,9 @@
 
 #include "gtkexpression.h"
 
+/* XXX: For g_memdup2() */
+#include "gtkprivate.h"
+
 #include <gobject/gvaluecollector.h>
 
 /**
@@ -685,7 +688,7 @@ gtk_expression_type_register_static (const char                  *type_name,
   info.base_finalize = NULL;
   info.class_init = gtk_expression_generic_class_init;
   info.class_finalize = NULL;
-  info.class_data = g_memdup (type_info, sizeof (GtkExpressionTypeInfo));
+  info.class_data = g_memdup2 (type_info, sizeof (GtkExpressionTypeInfo));
 
   info.instance_size = type_info->instance_size;
   info.n_preallocs = 0;
index bf119199b00328943b60556425e93479201c8646..d0e4d7083368643282ec22f62e030d81abd40ab8 100644 (file)
@@ -2831,7 +2831,7 @@ _gtk_range_get_stop_positions (GtkRange  *range,
   gtk_range_calc_marks (range);
 
   if (values)
-    *values = g_memdup (priv->mark_pos, priv->n_marks * sizeof (int));
+    *values = g_memdup2 (priv->mark_pos, priv->n_marks * sizeof (int));
 
   return priv->n_marks;
 }
index 172f58c4d59f5c3279a3277c84a4ee0527f569e2..74f3eb8655a54c262e75eef7289e72835b468265 100644 (file)
@@ -23,6 +23,9 @@
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcsstypesprivate.h"
 
+/* XXX: For g_memdup2() */
+#include "gtkprivate.h"
+
 #include <string.h>
 
 typedef struct {
@@ -106,7 +109,7 @@ append_arc (cairo_t *cr, double angle1, double angle2, gboolean negative)
         cairo_arc (tmp, 0.0, 0.0, 1.0, angle1, angle2);
 
       arc = fixup_path (cairo_copy_path (tmp));
-      g_hash_table_insert (arc_path_cache, g_memdup (&key, sizeof (key)), arc);
+      g_hash_table_insert (arc_path_cache, g_memdup2 (&key, sizeof (key)), arc);
 
       cairo_destroy (tmp);
       cairo_surface_destroy (surface);
index fe038ea18cf93d0cf5865382df8edcf362494583..84dee305fd105a1bcc48153adb1a6aa0db672d6f 100644 (file)
@@ -20,6 +20,7 @@
 #include "gtktreednd.h"
 #include "gtkintl.h"
 
+#include "gtkprivate.h"
 
 /**
  * SECTION:gtktreednd
@@ -245,7 +246,7 @@ struct _GtkTreeRowData
 static GtkTreeRowData *
 gtk_tree_row_data_copy (GtkTreeRowData *src)
 {
-  return g_memdup (src, sizeof (GtkTreeRowData) + strlen (src->path) + 1 -
+  return g_memdup2 (src, sizeof (GtkTreeRowData) + strlen (src->path) + 1 -
     (sizeof (GtkTreeRowData) - G_STRUCT_OFFSET (GtkTreeRowData, path)));
 }
 
index 6e69d66e3ce93711abcb683231a0b107b6bde0a9..10a6d80dc4226617bedafe054b325690c1d3fe4a 100644 (file)
@@ -87,6 +87,10 @@ typedef struct _GtkPrintBackendCupsClass GtkPrintBackendCupsClass;
 #define _CUPS_MAP_ATTR_INT(attr, v, a) {if (!g_ascii_strcasecmp (attr->name, (a))) v = attr->values[0].integer;}
 #define _CUPS_MAP_ATTR_STR(attr, v, a) {if (!g_ascii_strcasecmp (attr->name, (a))) v = attr->values[0].string.text;}
 
+#if !GLIB_CHECK_VERSION (2, 67, 3)
+# define g_memdup2(mem,size)    g_memdup((mem), (size))
+#endif
+
 typedef void (* GtkPrintCupsResponseCallbackFunc) (GtkPrintBackend *print_backend,
                                                    GtkCupsResult   *result,
                                                    gpointer         user_data);
@@ -6568,8 +6572,8 @@ localtime_to_utctime (const char *local_time)
       time_t rawtime;
       time (&rawtime);
 
-      actual_utc_time = g_memdup (gmtime (&rawtime), sizeof (struct tm));
-      actual_local_time = g_memdup (localtime (&rawtime), sizeof (struct tm));
+      actual_utc_time = g_memdup2 (gmtime (&rawtime), sizeof (struct tm));
+      actual_local_time = g_memdup2 (localtime (&rawtime), sizeof (struct tm));
 
       diff_time.tm_hour = actual_utc_time->tm_hour - actual_local_time->tm_hour;
       diff_time.tm_min  = actual_utc_time->tm_min  - actual_local_time->tm_min;