Commit be883434 authored by Philip Withnall's avatar Philip Withnall
Browse files

gio: Use g_memdup2() instead of g_memdup() in obvious places



Convert all the call sites which use `g_memdup()`’s length argument
trivially (for example, by passing a `sizeof()`), so that they use
`g_memdup2()` instead.

In almost all of these cases the use of `g_memdup()` would not have
caused problems, but it will soon be deprecated, so best port away from
it.
Signed-off-by: Philip Withnall's avatarPhilip Withnall <pwithnall@endlessos.org>
Helps: #2319
parent 5e5f75a7
...@@ -110,6 +110,7 @@ ...@@ -110,6 +110,7 @@
#include "gasyncinitable.h" #include "gasyncinitable.h"
#include "giostream.h" #include "giostream.h"
#include "gasyncresult.h" #include "gasyncresult.h"
#include "gstrfuncsprivate.h"
#include "gtask.h" #include "gtask.h"
#include "gmarshal-internal.h" #include "gmarshal-internal.h"
...@@ -4009,7 +4010,7 @@ _g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable) ...@@ -4009,7 +4010,7 @@ _g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable)
/* Don't waste memory by copying padding - remember to update this /* Don't waste memory by copying padding - remember to update this
* when changing struct _GDBusInterfaceVTable in gdbusconnection.h * when changing struct _GDBusInterfaceVTable in gdbusconnection.h
*/ */
return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer)); return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
} }
static void static void
...@@ -4026,7 +4027,7 @@ _g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable) ...@@ -4026,7 +4027,7 @@ _g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable)
/* Don't waste memory by copying padding - remember to update this /* Don't waste memory by copying padding - remember to update this
* when changing struct _GDBusSubtreeVTable in gdbusconnection.h * when changing struct _GDBusSubtreeVTable in gdbusconnection.h
*/ */
return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer)); return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
} }
static void static void
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "gdbusmethodinvocation.h" #include "gdbusmethodinvocation.h"
#include "gdbusconnection.h" #include "gdbusconnection.h"
#include "gmarshal-internal.h" #include "gmarshal-internal.h"
#include "gstrfuncsprivate.h"
#include "gtask.h" #include "gtask.h"
#include "gioerror.h" #include "gioerror.h"
...@@ -702,7 +703,7 @@ add_connection_locked (GDBusInterfaceSkeleton *interface_, ...@@ -702,7 +703,7 @@ add_connection_locked (GDBusInterfaceSkeleton *interface_,
* properly before building the hooked_vtable, so we create it * properly before building the hooked_vtable, so we create it
* once at the last minute. * once at the last minute.
*/ */
interface_->priv->hooked_vtable = g_memdup (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable)); interface_->priv->hooked_vtable = g_memdup2 (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
interface_->priv->hooked_vtable->method_call = skeleton_intercept_handle_method_call; interface_->priv->hooked_vtable->method_call = skeleton_intercept_handle_method_call;
} }
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include "gasyncresult.h" #include "gasyncresult.h"
#include "gioerror.h" #include "gioerror.h"
#include "glibintl.h" #include "glibintl.h"
#include "gstrfuncsprivate.h"
/** /**
...@@ -7871,7 +7872,7 @@ measure_disk_usage_progress (gboolean reporting, ...@@ -7871,7 +7872,7 @@ measure_disk_usage_progress (gboolean reporting,
g_main_context_invoke_full (g_task_get_context (task), g_main_context_invoke_full (g_task_get_context (task),
g_task_get_priority (task), g_task_get_priority (task),
measure_disk_usage_invoke_progress, measure_disk_usage_invoke_progress,
g_memdup (&progress, sizeof progress), g_memdup2 (&progress, sizeof progress),
g_free); g_free);
} }
...@@ -7889,7 +7890,7 @@ measure_disk_usage_thread (GTask *task, ...@@ -7889,7 +7890,7 @@ measure_disk_usage_thread (GTask *task,
data->progress_callback ? measure_disk_usage_progress : NULL, task, data->progress_callback ? measure_disk_usage_progress : NULL, task,
&result.disk_usage, &result.num_dirs, &result.num_files, &result.disk_usage, &result.num_dirs, &result.num_files,
&error)) &error))
g_task_return_pointer (task, g_memdup (&result, sizeof result), g_free); g_task_return_pointer (task, g_memdup2 (&result, sizeof result), g_free);
else else
g_task_return_error (task, error); g_task_return_error (task, error);
} }
...@@ -7913,7 +7914,7 @@ g_file_real_measure_disk_usage_async (GFile *file, ...@@ -7913,7 +7914,7 @@ g_file_real_measure_disk_usage_async (GFile *file,
task = g_task_new (file, cancellable, callback, user_data); task = g_task_new (file, cancellable, callback, user_data);
g_task_set_source_tag (task, g_file_real_measure_disk_usage_async); g_task_set_source_tag (task, g_file_real_measure_disk_usage_async);
g_task_set_task_data (task, g_memdup (&data, sizeof data), g_free); g_task_set_task_data (task, g_memdup2 (&data, sizeof data), g_free);
g_task_set_priority (task, io_priority); g_task_set_priority (task, io_priority);
g_task_run_in_thread (task, measure_disk_usage_thread); g_task_run_in_thread (task, measure_disk_usage_thread);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "glib-private.h" #include "glib-private.h"
#include "gsettingsschema-internal.h" #include "gsettingsschema-internal.h"
#include "gsettings.h" #include "gsettings.h"
#include "gstrfuncsprivate.h"
#include "gvdb/gvdb-reader.h" #include "gvdb/gvdb-reader.h"
#include "strinfo.c" #include "strinfo.c"
...@@ -1071,9 +1072,9 @@ g_settings_schema_list_children (GSettingsSchema *schema) ...@@ -1071,9 +1072,9 @@ g_settings_schema_list_children (GSettingsSchema *schema)
if (g_str_has_suffix (key, "/")) if (g_str_has_suffix (key, "/"))
{ {
gint length = strlen (key); gsize length = strlen (key);
strv[j] = g_memdup (key, length); strv[j] = g_memdup2 (key, length);
strv[j][length - 1] = '\0'; strv[j][length - 1] = '\0';
j++; j++;
} }
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <ntstatus.h> #include <ntstatus.h>
#include <winternl.h> #include <winternl.h>
#include "gstrfuncsprivate.h"
#ifndef _WDMDDK_ #ifndef _WDMDDK_
typedef enum _KEY_INFORMATION_CLASS { typedef enum _KEY_INFORMATION_CLASS {
KeyBasicInformation, KeyBasicInformation,
...@@ -247,7 +249,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter) ...@@ -247,7 +249,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
new_iter->value_name_size = iter->value_name_size; new_iter->value_name_size = iter->value_name_size;
if (iter->value_data != NULL) if (iter->value_data != NULL)
new_iter->value_data = g_memdup (iter->value_data, iter->value_data_size); new_iter->value_data = g_memdup2 (iter->value_data, iter->value_data_size);
new_iter->value_data_size = iter->value_data_size; new_iter->value_data_size = iter->value_data_size;
...@@ -268,7 +270,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter) ...@@ -268,7 +270,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
new_iter->value_data_expanded_charsize = iter->value_data_expanded_charsize; new_iter->value_data_expanded_charsize = iter->value_data_expanded_charsize;
if (iter->value_data_expanded_u8 != NULL) if (iter->value_data_expanded_u8 != NULL)
new_iter->value_data_expanded_u8 = g_memdup (iter->value_data_expanded_u8, new_iter->value_data_expanded_u8 = g_memdup2 (iter->value_data_expanded_u8,
iter->value_data_expanded_charsize); iter->value_data_expanded_charsize);
new_iter->value_data_expanded_u8_size = iter->value_data_expanded_charsize; new_iter->value_data_expanded_u8_size = iter->value_data_expanded_charsize;
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "gstrfuncsprivate.h"
#define DATA_TO_WRITE "Hello world\n" #define DATA_TO_WRITE "Hello world\n"
typedef struct typedef struct
...@@ -147,9 +149,9 @@ prepare_data (SetupData *data, ...@@ -147,9 +149,9 @@ prepare_data (SetupData *data,
data->expected_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->data_stream)); data->expected_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->data_stream));
g_assert_cmpint (data->expected_size, >, 0); g_assert_cmpuint (data->expected_size, >, 0);
data->expected_output = g_memdup (written, (guint)data->expected_size); data->expected_output = g_memdup2 (written, data->expected_size);
/* then recreate the streams and prepare them for the asynchronous close */ /* then recreate the streams and prepare them for the asynchronous close */
destroy_streams (data); destroy_streams (data);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include "gdbus-tests.h" #include "gdbus-tests.h"
#include "gstrfuncsprivate.h"
/* all tests rely on a shared mainloop */ /* all tests rely on a shared mainloop */
static GMainLoop *loop = NULL; static GMainLoop *loop = NULL;
...@@ -671,7 +672,7 @@ subtree_introspect (GDBusConnection *connection, ...@@ -671,7 +672,7 @@ subtree_introspect (GDBusConnection *connection,
g_assert_not_reached (); g_assert_not_reached ();
} }
return g_memdup (interfaces, 2 * sizeof (void *)); return g_memdup2 (interfaces, 2 * sizeof (void *));
} }
static const GDBusInterfaceVTable * static const GDBusInterfaceVTable *
...@@ -727,7 +728,7 @@ dynamic_subtree_introspect (GDBusConnection *connection, ...@@ -727,7 +728,7 @@ dynamic_subtree_introspect (GDBusConnection *connection,
{ {
const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL }; const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL };
return g_memdup (interfaces, 2 * sizeof (void *)); return g_memdup2 (interfaces, 2 * sizeof (void *));
} }
static const GDBusInterfaceVTable * static const GDBusInterfaceVTable *
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "gio/gfileattribute.h" #include "gio/gfileattribute.h"
#include "gio/gfileinfo.h" #include "gio/gfileinfo.h"
#include "gio/gfileinfo-priv.h" #include "gio/gfileinfo-priv.h"
#include "gstrfuncsprivate.h"
#include "gwinhttpfile.h" #include "gwinhttpfile.h"
#include "gwinhttpfileinputstream.h" #include "gwinhttpfileinputstream.h"
#include "gwinhttpfileoutputstream.h" #include "gwinhttpfileoutputstream.h"
...@@ -409,10 +410,10 @@ g_winhttp_file_resolve_relative_path (GFile *file, ...@@ -409,10 +410,10 @@ g_winhttp_file_resolve_relative_path (GFile *file,
child = g_object_new (G_TYPE_WINHTTP_FILE, NULL); child = g_object_new (G_TYPE_WINHTTP_FILE, NULL);
child->vfs = winhttp_file->vfs; child->vfs = winhttp_file->vfs;
child->url = winhttp_file->url; child->url = winhttp_file->url;
child->url.lpszScheme = g_memdup (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2); child->url.lpszScheme = g_memdup2 (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
child->url.lpszHostName = g_memdup (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2); child->url.lpszHostName = g_memdup2 (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
child->url.lpszUserName = g_memdup (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2); child->url.lpszUserName = g_memdup2 (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
child->url.lpszPassword = g_memdup (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2); child->url.lpszPassword = g_memdup2 (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
child->url.lpszUrlPath = wnew_path; child->url.lpszUrlPath = wnew_path;
child->url.dwUrlPathLength = wcslen (wnew_path); child->url.dwUrlPathLength = wcslen (wnew_path);
child->url.lpszExtraInfo = NULL; child->url.lpszExtraInfo = NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment