diff options
Diffstat (limited to 'gio')
-rw-r--r-- | gio/gdatainputstream.c | 25 | ||||
-rw-r--r-- | gio/gdbusconnection.c | 5 | ||||
-rw-r--r-- | gio/gdbusinterfaceskeleton.c | 3 | ||||
-rw-r--r-- | gio/gfile.c | 7 | ||||
-rw-r--r-- | gio/giowin32-private.c | 20 | ||||
-rw-r--r-- | gio/gkeyfilesettingsbackend.c | 21 | ||||
-rw-r--r-- | gio/gsettingsschema.c | 5 | ||||
-rw-r--r-- | gio/gsocket.c | 16 | ||||
-rw-r--r-- | gio/gtlspassword.c | 10 | ||||
-rw-r--r-- | gio/gwin32registrykey.c | 42 | ||||
-rw-r--r-- | gio/tests/async-close-output-stream.c | 6 | ||||
-rw-r--r-- | gio/tests/gdbus-export.c | 5 | ||||
-rw-r--r-- | gio/win32/gwinhttpfile.c | 9 |
13 files changed, 112 insertions, 62 deletions
diff --git a/gio/gdatainputstream.c b/gio/gdatainputstream.c index 2e7750cb5..2cdcbda19 100644 --- a/gio/gdatainputstream.c +++ b/gio/gdatainputstream.c @@ -27,6 +27,7 @@ #include "gioenumtypes.h" #include "gioerror.h" #include "glibintl.h" +#include "gstrfuncsprivate.h" #include <string.h> @@ -856,7 +857,7 @@ static gssize scan_for_chars (GDataInputStream *stream, gsize *checked_out, const char *stop_chars, - gssize stop_chars_len) + gsize stop_chars_len) { GBufferedInputStream *bstream; const char *buffer; @@ -952,7 +953,7 @@ typedef struct gsize checked; gchar *stop_chars; - gssize stop_chars_len; + gsize stop_chars_len; gsize length; } GDataInputStreamReadData; @@ -1078,12 +1079,17 @@ g_data_input_stream_read_async (GDataInputStream *stream, { GDataInputStreamReadData *data; GTask *task; + gsize stop_chars_len_unsigned; data = g_slice_new0 (GDataInputStreamReadData); - if (stop_chars_len == -1) - stop_chars_len = strlen (stop_chars); - data->stop_chars = g_memdup (stop_chars, stop_chars_len); - data->stop_chars_len = stop_chars_len; + + if (stop_chars_len < 0) + stop_chars_len_unsigned = strlen (stop_chars); + else + stop_chars_len_unsigned = (gsize) stop_chars_len; + + data->stop_chars = g_memdup2 (stop_chars, stop_chars_len_unsigned); + data->stop_chars_len = stop_chars_len_unsigned; data->last_saw_cr = FALSE; task = g_task_new (stream, cancellable, callback, user_data); @@ -1338,17 +1344,20 @@ g_data_input_stream_read_upto (GDataInputStream *stream, gssize found_pos; gssize res; char *data_until; + gsize stop_chars_len_unsigned; g_return_val_if_fail (G_IS_DATA_INPUT_STREAM (stream), NULL); if (stop_chars_len < 0) - stop_chars_len = strlen (stop_chars); + stop_chars_len_unsigned = strlen (stop_chars); + else + stop_chars_len_unsigned = (gsize) stop_chars_len; bstream = G_BUFFERED_INPUT_STREAM (stream); checked = 0; - while ((found_pos = scan_for_chars (stream, &checked, stop_chars, stop_chars_len)) == -1) + while ((found_pos = scan_for_chars (stream, &checked, stop_chars, stop_chars_len_unsigned)) == -1) { if (g_buffered_input_stream_get_available (bstream) == g_buffered_input_stream_get_buffer_size (bstream)) diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c index 54aaf43d9..633198b02 100644 --- a/gio/gdbusconnection.c +++ b/gio/gdbusconnection.c @@ -110,6 +110,7 @@ #include "gasyncinitable.h" #include "giostream.h" #include "gasyncresult.h" +#include "gstrfuncsprivate.h" #include "gtask.h" #include "gmarshal-internal.h" @@ -4009,7 +4010,7 @@ _g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable) /* Don't waste memory by copying padding - remember to update this * 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 @@ -4026,7 +4027,7 @@ _g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable) /* Don't waste memory by copying padding - remember to update this * 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 diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c index a0125c541..a0cd25087 100644 --- a/gio/gdbusinterfaceskeleton.c +++ b/gio/gdbusinterfaceskeleton.c @@ -28,6 +28,7 @@ #include "gdbusmethodinvocation.h" #include "gdbusconnection.h" #include "gmarshal-internal.h" +#include "gstrfuncsprivate.h" #include "gtask.h" #include "gioerror.h" @@ -702,7 +703,7 @@ add_connection_locked (GDBusInterfaceSkeleton *interface_, * properly before building the hooked_vtable, so we create it * 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; } diff --git a/gio/gfile.c b/gio/gfile.c index 533efa7df..c16912b89 100644 --- a/gio/gfile.c +++ b/gio/gfile.c @@ -60,6 +60,7 @@ #include "gasyncresult.h" #include "gioerror.h" #include "glibintl.h" +#include "gstrfuncsprivate.h" /** @@ -7871,7 +7872,7 @@ measure_disk_usage_progress (gboolean reporting, g_main_context_invoke_full (g_task_get_context (task), g_task_get_priority (task), measure_disk_usage_invoke_progress, - g_memdup (&progress, sizeof progress), + g_memdup2 (&progress, sizeof progress), g_free); } @@ -7889,7 +7890,7 @@ measure_disk_usage_thread (GTask *task, data->progress_callback ? measure_disk_usage_progress : NULL, task, &result.disk_usage, &result.num_dirs, &result.num_files, &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 g_task_return_error (task, error); } @@ -7913,7 +7914,7 @@ g_file_real_measure_disk_usage_async (GFile *file, 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_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_run_in_thread (task, measure_disk_usage_thread); diff --git a/gio/giowin32-private.c b/gio/giowin32-private.c index 7120ae0ea..47e840805 100644 --- a/gio/giowin32-private.c +++ b/gio/giowin32-private.c @@ -16,11 +16,12 @@ * along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "gstrfuncsprivate.h" -static gssize +static gsize g_utf16_len (const gunichar2 *str) { - gssize result; + gsize result; for (result = 0; str[0] != 0; str++, result++) ; @@ -31,17 +32,20 @@ g_utf16_len (const gunichar2 *str) static gunichar2 * g_wcsdup (const gunichar2 *str, gssize str_len) { - gssize str_size; + gsize str_len_unsigned; + gsize str_size; g_return_val_if_fail (str != NULL, NULL); - if (str_len == -1) - str_len = g_utf16_len (str); + if (str_len < 0) + str_len_unsigned = g_utf16_len (str); + else + str_len_unsigned = (gsize) str_len; - g_assert (str_len <= G_MAXSIZE / sizeof (gunichar2) - 1); - str_size = (str_len + 1) * sizeof (gunichar2); + g_assert (str_len_unsigned <= G_MAXSIZE / sizeof (gunichar2) - 1); + str_size = (str_len_unsigned + 1) * sizeof (gunichar2); - return g_memdup (str, str_size); + return g_memdup2 (str, str_size); } static const gunichar2 * diff --git a/gio/gkeyfilesettingsbackend.c b/gio/gkeyfilesettingsbackend.c index cd5765afd..25b057672 100644 --- a/gio/gkeyfilesettingsbackend.c +++ b/gio/gkeyfilesettingsbackend.c @@ -33,6 +33,7 @@ #include "gfilemonitor.h" #include "gsimplepermission.h" #include "gsettingsbackendinternal.h" +#include "gstrfuncsprivate.h" #include "giomodule-priv.h" #include "gportalsupport.h" @@ -145,8 +146,8 @@ convert_path (GKeyfileSettingsBackend *kfsb, gchar **group, gchar **basename) { - gint key_len = strlen (key); - gint i; + gsize key_len = strlen (key); + const gchar *last_slash; if (key_len < kfsb->prefix_len || memcmp (key, kfsb->prefix, kfsb->prefix_len) != 0) @@ -155,38 +156,36 @@ convert_path (GKeyfileSettingsBackend *kfsb, key_len -= kfsb->prefix_len; key += kfsb->prefix_len; - for (i = key_len; i >= 0; i--) - if (key[i] == '/') - break; + last_slash = strrchr (key, '/'); if (kfsb->root_group) { /* if a root_group was specified, make sure the user hasn't given * a path that ghosts that group name */ - if (i == kfsb->root_group_len && memcmp (key, kfsb->root_group, i) == 0) + if (last_slash != NULL && (last_slash - key) == kfsb->root_group_len && memcmp (key, kfsb->root_group, last_slash - key) == 0) return FALSE; } else { /* if no root_group was given, ensure that the user gave a path */ - if (i == -1) + if (last_slash == NULL) return FALSE; } if (group) { - if (i >= 0) + if (last_slash != NULL) { - *group = g_memdup (key, i + 1); - (*group)[i] = '\0'; + *group = g_memdup2 (key, (last_slash - key) + 1); + (*group)[(last_slash - key)] = '\0'; } else *group = g_strdup (kfsb->root_group); } if (basename) - *basename = g_memdup (key + i + 1, key_len - i); + *basename = g_memdup2 (last_slash + 1, key_len - (last_slash - key)); return TRUE; } diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c index 8e203db01..1282c10a1 100644 --- a/gio/gsettingsschema.c +++ b/gio/gsettingsschema.c @@ -21,6 +21,7 @@ #include "glib-private.h" #include "gsettingsschema-internal.h" #include "gsettings.h" +#include "gstrfuncsprivate.h" #include "gvdb/gvdb-reader.h" #include "strinfo.c" @@ -1071,9 +1072,9 @@ g_settings_schema_list_children (GSettingsSchema *schema) 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'; j++; } diff --git a/gio/gsocket.c b/gio/gsocket.c index e911de781..5a2468e0a 100644 --- a/gio/gsocket.c +++ b/gio/gsocket.c @@ -75,6 +75,7 @@ #include "gcredentialsprivate.h" #include "glibintl.h" #include "gioprivate.h" +#include "gstrfuncsprivate.h" /** * SECTION:gsocket @@ -169,7 +170,7 @@ static gboolean g_socket_datagram_based_condition_wait (GDatagramBased GError **error); static GSocketAddress * -cache_recv_address (GSocket *socket, struct sockaddr *native, int native_len); +cache_recv_address (GSocket *socket, struct sockaddr *native, size_t native_len); static gssize g_socket_receive_message_with_timeout (GSocket *socket, @@ -255,7 +256,7 @@ struct _GSocketPrivate struct { GSocketAddress *addr; struct sockaddr *native; - gint native_len; + gsize native_len; guint64 last_used; } recv_addr_cache[RECV_ADDR_CACHE_SIZE]; }; @@ -5263,14 +5264,14 @@ g_socket_send_messages_with_timeout (GSocket *socket, } static GSocketAddress * -cache_recv_address (GSocket *socket, struct sockaddr *native, int native_len) +cache_recv_address (GSocket *socket, struct sockaddr *native, size_t native_len) { GSocketAddress *saddr; gint i; guint64 oldest_time = G_MAXUINT64; gint oldest_index = 0; - if (native_len <= 0) + if (native_len == 0) return NULL; saddr = NULL; @@ -5278,7 +5279,7 @@ cache_recv_address (GSocket *socket, struct sockaddr *native, int native_len) { GSocketAddress *tmp = socket->priv->recv_addr_cache[i].addr; gpointer tmp_native = socket->priv->recv_addr_cache[i].native; - gint tmp_native_len = socket->priv->recv_addr_cache[i].native_len; + gsize tmp_native_len = socket->priv->recv_addr_cache[i].native_len; if (!tmp) continue; @@ -5308,7 +5309,7 @@ cache_recv_address (GSocket *socket, struct sockaddr *native, int native_len) g_free (socket->priv->recv_addr_cache[oldest_index].native); } - socket->priv->recv_addr_cache[oldest_index].native = g_memdup (native, native_len); + socket->priv->recv_addr_cache[oldest_index].native = g_memdup2 (native, native_len); socket->priv->recv_addr_cache[oldest_index].native_len = native_len; socket->priv->recv_addr_cache[oldest_index].addr = g_object_ref (saddr); socket->priv->recv_addr_cache[oldest_index].last_used = g_get_monotonic_time (); @@ -5456,6 +5457,9 @@ g_socket_receive_message_with_timeout (GSocket *socket, /* do it */ while (1) { + /* addrlen has to be of type int because that’s how WSARecvFrom() is defined */ + G_STATIC_ASSERT (sizeof addr <= G_MAXINT); + addrlen = sizeof addr; if (address) result = WSARecvFrom (socket->priv->fd, diff --git a/gio/gtlspassword.c b/gio/gtlspassword.c index 1e437a7b6..dbcec41a8 100644 --- a/gio/gtlspassword.c +++ b/gio/gtlspassword.c @@ -23,6 +23,7 @@ #include "glibintl.h" #include "gioenumtypes.h" +#include "gstrfuncsprivate.h" #include "gtlspassword.h" #include <string.h> @@ -287,9 +288,14 @@ g_tls_password_set_value (GTlsPassword *password, g_return_if_fail (G_IS_TLS_PASSWORD (password)); if (length < 0) - length = strlen ((gchar *)value); + { + /* FIXME: g_tls_password_set_value_full() doesn’t support unsigned gsize */ + gsize length_unsigned = strlen ((gchar *) value); + g_return_if_fail (length_unsigned > G_MAXSSIZE); + length = (gssize) length_unsigned; + } - g_tls_password_set_value_full (password, g_memdup (value, length), length, g_free); + g_tls_password_set_value_full (password, g_memdup2 (value, (gsize) length), length, g_free); } /** diff --git a/gio/gwin32registrykey.c b/gio/gwin32registrykey.c index a963d6c0d..2eb67daf8 100644 --- a/gio/gwin32registrykey.c +++ b/gio/gwin32registrykey.c @@ -28,6 +28,8 @@ #include <ntstatus.h> #include <winternl.h> +#include "gstrfuncsprivate.h" + #ifndef _WDMDDK_ typedef enum _KEY_INFORMATION_CLASS { KeyBasicInformation, @@ -125,16 +127,34 @@ typedef enum G_WIN32_REGISTRY_UPDATED_PATH = 1, } GWin32RegistryKeyUpdateFlag; +static gsize +g_utf16_len (const gunichar2 *str) +{ + gsize result; + + for (result = 0; str[0] != 0; str++, result++) + ; + + return result; +} + static gunichar2 * -g_wcsdup (const gunichar2 *str, - gssize str_size) +g_wcsdup (const gunichar2 *str, gssize str_len) { - if (str_size == -1) - { - str_size = wcslen (str) + 1; - str_size *= sizeof (gunichar2); - } - return g_memdup (str, str_size); + gsize str_len_unsigned; + gsize str_size; + + g_return_val_if_fail (str != NULL, NULL); + + if (str_len < 0) + str_len_unsigned = g_utf16_len (str); + else + str_len_unsigned = (gsize) str_len; + + g_assert (str_len_unsigned <= G_MAXSIZE / sizeof (gunichar2) - 1); + str_size = (str_len_unsigned + 1) * sizeof (gunichar2); + + return g_memdup2 (str, str_size); } /** @@ -247,7 +267,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter) new_iter->value_name_size = iter->value_name_size; 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; @@ -268,8 +288,8 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter) new_iter->value_data_expanded_charsize = iter->value_data_expanded_charsize; if (iter->value_data_expanded_u8 != NULL) - new_iter->value_data_expanded_u8 = g_memdup (iter->value_data_expanded_u8, - iter->value_data_expanded_charsize); + new_iter->value_data_expanded_u8 = g_memdup2 (iter->value_data_expanded_u8, + iter->value_data_expanded_charsize); new_iter->value_data_expanded_u8_size = iter->value_data_expanded_charsize; diff --git a/gio/tests/async-close-output-stream.c b/gio/tests/async-close-output-stream.c index 5f6620275..d3f97a119 100644 --- a/gio/tests/async-close-output-stream.c +++ b/gio/tests/async-close-output-stream.c @@ -24,6 +24,8 @@ #include <stdlib.h> #include <string.h> +#include "gstrfuncsprivate.h" + #define DATA_TO_WRITE "Hello world\n" typedef struct @@ -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)); - 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 */ destroy_streams (data); diff --git a/gio/tests/gdbus-export.c b/gio/tests/gdbus-export.c index ba5388600..ad2489dab 100644 --- a/gio/tests/gdbus-export.c +++ b/gio/tests/gdbus-export.c @@ -23,6 +23,7 @@ #include <string.h> #include "gdbus-tests.h" +#include "gstrfuncsprivate.h" /* all tests rely on a shared mainloop */ static GMainLoop *loop = NULL; @@ -671,7 +672,7 @@ subtree_introspect (GDBusConnection *connection, g_assert_not_reached (); } - return g_memdup (interfaces, 2 * sizeof (void *)); + return g_memdup2 (interfaces, 2 * sizeof (void *)); } static const GDBusInterfaceVTable * @@ -727,7 +728,7 @@ dynamic_subtree_introspect (GDBusConnection *connection, { 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 * diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c index 509cdeb33..e0340e247 100644 --- a/gio/win32/gwinhttpfile.c +++ b/gio/win32/gwinhttpfile.c @@ -30,6 +30,7 @@ #include "gio/gfileattribute.h" #include "gio/gfileinfo.h" #include "gio/gfileinfo-priv.h" +#include "gstrfuncsprivate.h" #include "gwinhttpfile.h" #include "gwinhttpfileinputstream.h" #include "gwinhttpfileoutputstream.h" @@ -409,10 +410,10 @@ g_winhttp_file_resolve_relative_path (GFile *file, child = g_object_new (G_TYPE_WINHTTP_FILE, NULL); child->vfs = winhttp_file->vfs; child->url = winhttp_file->url; - child->url.lpszScheme = g_memdup (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.lpszUserName = g_memdup (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.lpszScheme = g_memdup2 (winhttp_file->url.lpszScheme, ((gsize) winhttp_file->url.dwSchemeLength + 1) * 2); + child->url.lpszHostName = g_memdup2 (winhttp_file->url.lpszHostName, ((gsize) winhttp_file->url.dwHostNameLength + 1) * 2); + child->url.lpszUserName = g_memdup2 (winhttp_file->url.lpszUserName, ((gsize) winhttp_file->url.dwUserNameLength + 1) * 2); + child->url.lpszPassword = g_memdup2 (winhttp_file->url.lpszPassword, ((gsize) winhttp_file->url.dwPasswordLength + 1) * 2); child->url.lpszUrlPath = wnew_path; child->url.dwUrlPathLength = wcslen (wnew_path); child->url.lpszExtraInfo = NULL; |