Blame SOURCES/0002-gio-Use-g_memdup2-instead-of-g_memdup-in-obvious-pla.patch

e5da31
From d27057acbb26f5b3400677e22a7801bb60a9a134 Mon Sep 17 00:00:00 2001
e5da31
From: Philip Withnall <pwithnall@endlessos.org>
e5da31
Date: Thu, 4 Feb 2021 13:37:56 +0000
e5da31
Subject: [PATCH 02/12] gio: Use g_memdup2() instead of g_memdup() in obvious
e5da31
 places
e5da31
MIME-Version: 1.0
e5da31
Content-Type: text/plain; charset=UTF-8
e5da31
Content-Transfer-Encoding: 8bit
e5da31
e5da31
Convert all the call sites which use `g_memdup()`’s length argument
e5da31
trivially (for example, by passing a `sizeof()`), so that they use
e5da31
`g_memdup2()` instead.
e5da31
e5da31
In almost all of these cases the use of `g_memdup()` would not have
e5da31
caused problems, but it will soon be deprecated, so best port away from
e5da31
it.
e5da31
e5da31
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
e5da31
Helps: #2319
e5da31
---
e5da31
 gio/gdbusconnection.c                 | 5 +++--
e5da31
 gio/gdbusinterfaceskeleton.c          | 3 ++-
e5da31
 gio/gfile.c                           | 7 ++++---
e5da31
 gio/gsettingsschema.c                 | 5 +++--
e5da31
 gio/gwin32registrykey.c               | 8 +++++---
e5da31
 gio/tests/async-close-output-stream.c | 6 ++++--
e5da31
 gio/tests/gdbus-export.c              | 5 +++--
e5da31
 gio/win32/gwinhttpfile.c              | 9 +++++----
e5da31
 8 files changed, 29 insertions(+), 19 deletions(-)
e5da31
e5da31
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
e5da31
index 6f7e5fefc..117c8df35 100644
e5da31
--- a/gio/gdbusconnection.c
e5da31
+++ b/gio/gdbusconnection.c
e5da31
@@ -119,6 +119,7 @@
e5da31
 #include "gasyncinitable.h"
e5da31
 #include "giostream.h"
e5da31
 #include "gasyncresult.h"
e5da31
+#include "gstrfuncsprivate.h"
e5da31
 #include "gtask.h"
e5da31
 
e5da31
 #ifdef G_OS_UNIX
e5da31
@@ -3970,7 +3971,7 @@ _g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable)
e5da31
   /* Don't waste memory by copying padding - remember to update this
e5da31
    * when changing struct _GDBusInterfaceVTable in gdbusconnection.h
e5da31
    */
e5da31
-  return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
e5da31
+  return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
e5da31
 }
e5da31
 
e5da31
 static void
e5da31
@@ -3987,7 +3988,7 @@ _g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable)
e5da31
   /* Don't waste memory by copying padding - remember to update this
e5da31
    * when changing struct _GDBusSubtreeVTable in gdbusconnection.h
e5da31
    */
e5da31
-  return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
e5da31
+  return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
e5da31
 }
e5da31
 
e5da31
 static void
e5da31
diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c
e5da31
index 96bd520aa..672604c49 100644
e5da31
--- a/gio/gdbusinterfaceskeleton.c
e5da31
+++ b/gio/gdbusinterfaceskeleton.c
e5da31
@@ -27,6 +27,7 @@
e5da31
 #include "gdbusprivate.h"
e5da31
 #include "gdbusmethodinvocation.h"
e5da31
 #include "gdbusconnection.h"
e5da31
+#include "gstrfuncsprivate.h"
e5da31
 #include "gtask.h"
e5da31
 #include "gioerror.h"
e5da31
 
e5da31
@@ -697,7 +698,7 @@ add_connection_locked (GDBusInterfaceSkeleton *interface_,
e5da31
        * properly before building the hooked_vtable, so we create it
e5da31
        * once at the last minute.
e5da31
        */
e5da31
-      interface_->priv->hooked_vtable = g_memdup (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
e5da31
+      interface_->priv->hooked_vtable = g_memdup2 (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
e5da31
       interface_->priv->hooked_vtable->method_call = skeleton_intercept_handle_method_call;
e5da31
     }
e5da31
 
e5da31
diff --git a/gio/gfile.c b/gio/gfile.c
e5da31
index ff313ebf8..29ebaaa62 100644
e5da31
--- a/gio/gfile.c
e5da31
+++ b/gio/gfile.c
e5da31
@@ -60,6 +60,7 @@
e5da31
 #include "gasyncresult.h"
e5da31
 #include "gioerror.h"
e5da31
 #include "glibintl.h"
e5da31
+#include "gstrfuncsprivate.h"
e5da31
 
e5da31
 
e5da31
 /**
e5da31
@@ -7734,7 +7735,7 @@ measure_disk_usage_progress (gboolean reporting,
e5da31
   g_main_context_invoke_full (g_task_get_context (task),
e5da31
                               g_task_get_priority (task),
e5da31
                               measure_disk_usage_invoke_progress,
e5da31
-                              g_memdup (&progress, sizeof progress),
e5da31
+                              g_memdup2 (&progress, sizeof progress),
e5da31
                               g_free);
e5da31
 }
e5da31
 
e5da31
@@ -7752,7 +7753,7 @@ measure_disk_usage_thread (GTask        *task,
e5da31
                                  data->progress_callback ? measure_disk_usage_progress : NULL, task,
e5da31
                                  &result.disk_usage, &result.num_dirs, &result.num_files,
e5da31
                                  &error))
e5da31
-    g_task_return_pointer (task, g_memdup (&result, sizeof result), g_free);
e5da31
+    g_task_return_pointer (task, g_memdup2 (&result, sizeof result), g_free);
e5da31
   else
e5da31
     g_task_return_error (task, error);
e5da31
 }
e5da31
@@ -7776,7 +7777,7 @@ g_file_real_measure_disk_usage_async (GFile                        *file,
e5da31
 
e5da31
   task = g_task_new (file, cancellable, callback, user_data);
e5da31
   g_task_set_source_tag (task, g_file_real_measure_disk_usage_async);
e5da31
-  g_task_set_task_data (task, g_memdup (&data, sizeof data), g_free);
e5da31
+  g_task_set_task_data (task, g_memdup2 (&data, sizeof data), g_free);
e5da31
   g_task_set_priority (task, io_priority);
e5da31
 
e5da31
   g_task_run_in_thread (task, measure_disk_usage_thread);
e5da31
diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
e5da31
index 17b7e3b01..499944395 100644
e5da31
--- a/gio/gsettingsschema.c
e5da31
+++ b/gio/gsettingsschema.c
e5da31
@@ -20,6 +20,7 @@
e5da31
 
e5da31
 #include "gsettingsschema-internal.h"
e5da31
 #include "gsettings.h"
e5da31
+#include "gstrfuncsprivate.h"
e5da31
 
e5da31
 #include "gvdb/gvdb-reader.h"
e5da31
 #include "strinfo.c"
e5da31
@@ -1054,9 +1055,9 @@ g_settings_schema_list_children (GSettingsSchema *schema)
e5da31
 
e5da31
       if (g_str_has_suffix (key, "/"))
e5da31
         {
e5da31
-          gint length = strlen (key);
e5da31
+          gsize length = strlen (key);
e5da31
 
e5da31
-          strv[j] = g_memdup (key, length);
e5da31
+          strv[j] = g_memdup2 (key, length);
e5da31
           strv[j][length - 1] = '\0';
e5da31
           j++;
e5da31
         }
e5da31
diff --git a/gio/gwin32registrykey.c b/gio/gwin32registrykey.c
e5da31
index c19fede4e..619fd48af 100644
e5da31
--- a/gio/gwin32registrykey.c
e5da31
+++ b/gio/gwin32registrykey.c
e5da31
@@ -28,6 +28,8 @@
e5da31
 #include <ntstatus.h>
e5da31
 #include <winternl.h>
e5da31
 
e5da31
+#include "gstrfuncsprivate.h"
e5da31
+
e5da31
 #ifndef _WDMDDK_
e5da31
 typedef enum _KEY_INFORMATION_CLASS {
e5da31
   KeyBasicInformation,
e5da31
@@ -247,7 +249,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
e5da31
   new_iter->value_name_size = iter->value_name_size;
e5da31
 
e5da31
   if (iter->value_data != NULL)
e5da31
-    new_iter->value_data = g_memdup (iter->value_data, iter->value_data_size);
e5da31
+    new_iter->value_data = g_memdup2 (iter->value_data, iter->value_data_size);
e5da31
 
e5da31
   new_iter->value_data_size = iter->value_data_size;
e5da31
 
e5da31
@@ -268,8 +270,8 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
e5da31
   new_iter->value_data_expanded_charsize = iter->value_data_expanded_charsize;
e5da31
 
e5da31
   if (iter->value_data_expanded_u8 != NULL)
e5da31
-    new_iter->value_data_expanded_u8 = g_memdup (iter->value_data_expanded_u8,
e5da31
-                                                 iter->value_data_expanded_charsize);
e5da31
+    new_iter->value_data_expanded_u8 = g_memdup2 (iter->value_data_expanded_u8,
e5da31
+                                                  iter->value_data_expanded_charsize);
e5da31
 
e5da31
   new_iter->value_data_expanded_u8_size = iter->value_data_expanded_charsize;
e5da31
 
e5da31
diff --git a/gio/tests/async-close-output-stream.c b/gio/tests/async-close-output-stream.c
e5da31
index 5f6620275..d3f97a119 100644
e5da31
--- a/gio/tests/async-close-output-stream.c
e5da31
+++ b/gio/tests/async-close-output-stream.c
e5da31
@@ -24,6 +24,8 @@
e5da31
 #include <stdlib.h>
e5da31
 #include <string.h>
e5da31
 
e5da31
+#include "gstrfuncsprivate.h"
e5da31
+
e5da31
 #define DATA_TO_WRITE "Hello world\n"
e5da31
 
e5da31
 typedef struct
e5da31
@@ -147,9 +149,9 @@ prepare_data (SetupData *data,
e5da31
 
e5da31
   data->expected_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->data_stream));
e5da31
 
e5da31
-  g_assert_cmpint (data->expected_size, >, 0);
e5da31
+  g_assert_cmpuint (data->expected_size, >, 0);
e5da31
 
e5da31
-  data->expected_output = g_memdup (written, (guint)data->expected_size);
e5da31
+  data->expected_output = g_memdup2 (written, data->expected_size);
e5da31
 
e5da31
   /* then recreate the streams and prepare them for the asynchronous close */
e5da31
   destroy_streams (data);
e5da31
diff --git a/gio/tests/gdbus-export.c b/gio/tests/gdbus-export.c
e5da31
index ef0dddeee..a3c842360 100644
e5da31
--- a/gio/tests/gdbus-export.c
e5da31
+++ b/gio/tests/gdbus-export.c
e5da31
@@ -23,6 +23,7 @@
e5da31
 #include <string.h>
e5da31
 
e5da31
 #include "gdbus-tests.h"
e5da31
+#include "gstrfuncsprivate.h"
e5da31
 
e5da31
 /* all tests rely on a shared mainloop */
e5da31
 static GMainLoop *loop = NULL;
e5da31
@@ -652,7 +653,7 @@ subtree_introspect (GDBusConnection       *connection,
e5da31
       g_assert_not_reached ();
e5da31
     }
e5da31
 
e5da31
-  return g_memdup (interfaces, 2 * sizeof (void *));
e5da31
+  return g_memdup2 (interfaces, 2 * sizeof (void *));
e5da31
 }
e5da31
 
e5da31
 static const GDBusInterfaceVTable *
e5da31
@@ -708,7 +709,7 @@ dynamic_subtree_introspect (GDBusConnection       *connection,
e5da31
 {
e5da31
   const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL };
e5da31
 
e5da31
-  return g_memdup (interfaces, 2 * sizeof (void *));
e5da31
+  return g_memdup2 (interfaces, 2 * sizeof (void *));
e5da31
 }
e5da31
 
e5da31
 static const GDBusInterfaceVTable *
e5da31
diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c
e5da31
index d5df16d91..f424d21cc 100644
e5da31
--- a/gio/win32/gwinhttpfile.c
e5da31
+++ b/gio/win32/gwinhttpfile.c
e5da31
@@ -29,6 +29,7 @@
e5da31
 #include "gio/gfile.h"
e5da31
 #include "gio/gfileattribute.h"
e5da31
 #include "gio/gfileinfo.h"
e5da31
+#include "gstrfuncsprivate.h"
e5da31
 #include "gwinhttpfile.h"
e5da31
 #include "gwinhttpfileinputstream.h"
e5da31
 #include "gwinhttpfileoutputstream.h"
e5da31
@@ -393,10 +394,10 @@ g_winhttp_file_resolve_relative_path (GFile      *file,
e5da31
   child = g_object_new (G_TYPE_WINHTTP_FILE, NULL);
e5da31
   child->vfs = winhttp_file->vfs;
e5da31
   child->url = winhttp_file->url;
e5da31
-  child->url.lpszScheme = g_memdup (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
e5da31
-  child->url.lpszHostName = g_memdup (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
e5da31
-  child->url.lpszUserName = g_memdup (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
e5da31
-  child->url.lpszPassword = g_memdup (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
e5da31
+  child->url.lpszScheme = g_memdup2 (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
e5da31
+  child->url.lpszHostName = g_memdup2 (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
e5da31
+  child->url.lpszUserName = g_memdup2 (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
e5da31
+  child->url.lpszPassword = g_memdup2 (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
e5da31
   child->url.lpszUrlPath = wnew_path;
e5da31
   child->url.dwUrlPathLength = wcslen (wnew_path);
e5da31
   child->url.lpszExtraInfo = NULL;
e5da31
-- 
e5da31
2.31.1
e5da31