diff --git a/gio/gapplicationcommandline.c b/gio/gapplicationcommandline.c index b3a6d00b4..dcd3301d9 100644 --- a/gio/gapplicationcommandline.c +++ b/gio/gapplicationcommandline.c @@ -666,8 +666,8 @@ const gchar * g_application_command_line_getenv (GApplicationCommandLine *cmdline, const gchar *name) { - gint length = strlen (name); - gint i; + size_t length = strlen (name); + size_t i; /* TODO: expand on windows */ if (cmdline->priv->environ) diff --git a/gio/gdbus-tool.c b/gio/gdbus-tool.c index 63c7ec9dc..53e22ebdd 100644 --- a/gio/gdbus-tool.c +++ b/gio/gdbus-tool.c @@ -1373,7 +1373,7 @@ dump_method (const GDBusMethodInfo *o, { guint n; guint m; - guint name_len; + size_t name_len; guint total_num_args; for (n = 0; o->annotations != NULL && o->annotations[n] != NULL; n++) diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c index 1b31f4b67..2e170a4e2 100644 --- a/gio/gdbusconnection.c +++ b/gio/gdbusconnection.c @@ -3822,8 +3822,8 @@ static gboolean namespace_rule_matches (const gchar *namespace, const gchar *name) { - gint len_namespace; - gint len_name; + size_t len_namespace; + size_t len_name; len_namespace = strlen (namespace); len_name = strlen (name); @@ -3841,7 +3841,7 @@ static gboolean path_rule_matches (const gchar *path_a, const gchar *path_b) { - gint len_a, len_b; + size_t len_a, len_b; len_a = strlen (path_a); len_b = strlen (path_b); diff --git a/gio/gdbusdaemon.c b/gio/gdbusdaemon.c index 3474b7091..8ad85b9d7 100644 --- a/gio/gdbusdaemon.c +++ b/gio/gdbusdaemon.c @@ -543,7 +543,8 @@ match_matches (GDBusDaemon *daemon, { MatchElement *element; Name *name; - int i, len, len2; + int i; + size_t len, len2; const char *value; int check_type; diff --git a/gio/gdbusmessage.c b/gio/gdbusmessage.c index 5a5fec880..0b77dc607 100644 --- a/gio/gdbusmessage.c +++ b/gio/gdbusmessage.c @@ -2852,7 +2852,7 @@ append_value_to_blob (GVariant *value, const gchar *signature; child = g_variant_get_child_value (value, 0); signature = g_variant_get_type_string (child); - g_memory_buffer_put_byte (mbuf, strlen (signature)); + g_memory_buffer_put_byte (mbuf, (guint8) strlen (signature)); /* signature is already validated to be this short */ g_memory_buffer_put_string (mbuf, signature); g_memory_buffer_put_byte (mbuf, '\0'); if (!append_value_to_blob (child, diff --git a/gio/gdbusutils.c b/gio/gdbusutils.c index a76e9ac1a..70825a557 100644 --- a/gio/gdbusutils.c +++ b/gio/gdbusutils.c @@ -113,7 +113,7 @@ is_valid_name (const gchar *start, gboolean g_dbus_is_name (const gchar *string) { - guint len; + size_t len; gboolean ret; const gchar *s; diff --git a/gio/gdummyfile.c b/gio/gdummyfile.c index 4ec352c6e..230977668 100644 --- a/gio/gdummyfile.c +++ b/gio/gdummyfile.c @@ -239,7 +239,7 @@ static const char * match_prefix (const char *path, const char *prefix) { - int prefix_len; + size_t prefix_len; prefix_len = strlen (prefix); if (strncmp (path, prefix, prefix_len) != 0) diff --git a/gio/gfilenamecompleter.c b/gio/gfilenamecompleter.c index aca42498a..295ade05b 100644 --- a/gio/gfilenamecompleter.c +++ b/gio/gfilenamecompleter.c @@ -345,7 +345,7 @@ init_completion (GFilenameCompleter *completer, GFile *file, *parent; char *basename; char *t; - int len; + size_t len; *basename_out = NULL; diff --git a/gio/gio-tool-mount.c b/gio/gio-tool-mount.c index 13a78f7ca..5a35c1b36 100644 --- a/gio/gio-tool-mount.c +++ b/gio/gio-tool-mount.c @@ -89,7 +89,7 @@ prompt_for (const char *prompt, const char *default_value, gboolean echo) gboolean restore_flags; #endif char data[256]; - int len; + size_t len; if (default_value && *default_value != 0) g_print ("%s [%s]: ", prompt, default_value); diff --git a/gio/gio-tool-set.c b/gio/gio-tool-set.c index 02622ba9e..324ee84de 100644 --- a/gio/gio-tool-set.c +++ b/gio/gio-tool-set.c @@ -42,10 +42,10 @@ static const GOptionEntry entries[] = { static char * hex_unescape (const char *str) { - int i; + size_t i; char *unescaped_str, *p; unsigned char c; - int len; + size_t len; len = strlen (str); unescaped_str = g_malloc (len + 1); diff --git a/gio/glib-compile-schemas.c b/gio/glib-compile-schemas.c index 04ef40457..54b980b0c 100644 --- a/gio/glib-compile-schemas.c +++ b/gio/glib-compile-schemas.c @@ -680,7 +680,7 @@ key_state_serialise (KeyState *state) if (state->l10n_context) { - gint len; + size_t len; /* Contextified messages are supported by prepending * the context, followed by '\004' to the start of the diff --git a/gio/glocalfile.c b/gio/glocalfile.c index ceb888ad8..69dd60f81 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -479,7 +479,7 @@ static const char * match_prefix (const char *path, const char *prefix) { - int prefix_len; + size_t prefix_len; prefix_len = strlen (prefix); if (strncmp (path, prefix, prefix_len) != 0) diff --git a/gio/gresource-tool.c b/gio/gresource-tool.c index 44b1f3f02..b6b51e763 100644 --- a/gio/gresource-tool.c +++ b/gio/gresource-tool.c @@ -83,7 +83,7 @@ list_resource (GResource *resource, gint i; gchar *child; GError *error = NULL; - gint len; + size_t len; children = g_resource_enumerate_children (resource, path, 0, &error); if (error) diff --git a/gio/gresource.c b/gio/gresource.c index d19adf312..9454db3bf 100644 --- a/gio/gresource.c +++ b/gio/gresource.c @@ -352,7 +352,7 @@ g_resource_find_overlay (const gchar *path, /* This is a null-terminated array of replacement strings (with '=' inside) */ static const gchar * const *overlay_dirs; gboolean res = FALSE; - gint path_len = -1; + size_t path_len = 0; gint i; /* We try to be very fast in case there are no overlays. Otherwise, @@ -449,9 +449,9 @@ g_resource_find_overlay (const gchar *path, for (i = 0; overlay_dirs[i]; i++) { const gchar *src; - gint src_len; + size_t src_len; const gchar *dst; - gint dst_len; + size_t dst_len; gchar *candidate; { @@ -466,7 +466,7 @@ g_resource_find_overlay (const gchar *path, /* hold off on dst_len because we will probably fail the checks below */ } - if (path_len == -1) + if (i == 0) path_len = strlen (path); /* The entire path is too short to match the source */ diff --git a/gio/gresourcefile.c b/gio/gresourcefile.c index 1621839cf..2fe37fdcc 100644 --- a/gio/gresourcefile.c +++ b/gio/gresourcefile.c @@ -354,7 +354,7 @@ static const char * match_prefix (const char *path, const char *prefix) { - int prefix_len; + size_t prefix_len; prefix_len = strlen (prefix); if (strncmp (path, prefix, prefix_len) != 0) diff --git a/gio/gsocks5proxy.c b/gio/gsocks5proxy.c index 71ac107da..42623391c 100644 --- a/gio/gsocks5proxy.c +++ b/gio/gsocks5proxy.c @@ -114,10 +114,10 @@ g_socks5_proxy_init (GSocks5Proxy *proxy) * +----+----------+----------+ */ #define SOCKS5_NEGO_MSG_LEN 4 -static gint +static size_t set_nego_msg (guint8 *msg, gboolean has_auth) { - gint len = 3; + size_t len = 3; msg[0] = SOCKS5_VERSION; msg[1] = 0x01; /* number of methods supported */ @@ -200,15 +200,20 @@ parse_nego_reply (const guint8 *data, } #define SOCKS5_AUTH_MSG_LEN 515 -static gint -set_auth_msg (guint8 *msg, - const gchar *username, - const gchar *password, - GError **error) +static gboolean +set_auth_msg (guint8 *msg, + const gchar *username, + const gchar *password, + size_t *out_len, + GError **error) { - gint len = 0; - gint ulen = 0; /* username length */ - gint plen = 0; /* Password length */ + size_t len = 0; + size_t ulen = 0; /* username length */ + size_t plen = 0; /* Password length */ + + /* Clear output first */ + if (out_len != NULL) + *out_len = 0; if (username) ulen = strlen (username); @@ -221,7 +226,7 @@ set_auth_msg (guint8 *msg, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PROXY_FAILED, _("Username or password is too long for SOCKSv5 " "protocol.")); - return -1; + return FALSE; } msg[len++] = SOCKS5_AUTH_VERSION; @@ -238,7 +243,10 @@ set_auth_msg (guint8 *msg, len += plen; - return len; + if (out_len != NULL) + *out_len = len; + + return TRUE; } @@ -266,13 +274,18 @@ check_auth_status (const guint8 *data, GError **error) * longer then 256 bytes. */ #define SOCKS5_CONN_MSG_LEN 262 -static gint +static gboolean set_connect_msg (guint8 *msg, - const gchar *hostname, - guint16 port, - GError **error) + const gchar *hostname, + guint16 port, + size_t *out_len, + GError **error) { - guint len = 0; + size_t len = 0; + + /* Clear output first */ + if (out_len != NULL) + *out_len = 0; msg[len++] = SOCKS5_VERSION; msg[len++] = SOCKS5_CMD_CONNECT; @@ -301,7 +314,7 @@ set_connect_msg (guint8 *msg, g_set_error (error, G_IO_ERROR, G_IO_ERROR_PROXY_FAILED, _("Hostname “%s” is too long for SOCKSv5 protocol"), hostname); - return -1; + return FALSE; } msg[len++] = SOCKS5_ATYP_DOMAINNAME; @@ -316,7 +329,10 @@ set_connect_msg (guint8 *msg, len += 2; } - return len; + if (out_len != NULL) + *out_len = len; + + return TRUE; } /* @@ -447,7 +463,7 @@ g_socks5_proxy_connect (GProxy *proxy, /* Send SOCKS5 handshake */ { guint8 msg[SOCKS5_NEGO_MSG_LEN]; - gint len; + size_t len; len = set_nego_msg (msg, has_auth); @@ -471,12 +487,10 @@ g_socks5_proxy_connect (GProxy *proxy, if (must_auth) { guint8 msg[SOCKS5_AUTH_MSG_LEN]; - gint len; + size_t len; - len = set_auth_msg (msg, username, password, error); - - if (len < 0) - goto error; + if (!set_auth_msg (msg, username, password, &len, error)) + goto error; if (!g_output_stream_write_all (out, msg, len, NULL, cancellable, error)) @@ -494,12 +508,10 @@ g_socks5_proxy_connect (GProxy *proxy, /* Send SOCKS5 connection request */ { guint8 msg[SOCKS5_CONN_MSG_LEN]; - gint len; + size_t len; - len = set_connect_msg (msg, hostname, port, error); - - if (len < 0) - goto error; + if (!set_connect_msg (msg, hostname, port, &len, error)) + goto error; if (!g_output_stream_write_all (out, msg, len, NULL, cancellable, error)) @@ -561,8 +573,8 @@ typedef struct gchar *username; gchar *password; guint8 *buffer; - gssize length; - gssize offset; + size_t length; + size_t offset; } ConnectAsyncData; static void nego_msg_write_cb (GObject *source, @@ -751,13 +763,13 @@ nego_reply_read_cb (GObject *source, g_free (data->buffer); data->buffer = g_malloc0 (SOCKS5_AUTH_MSG_LEN); - data->length = set_auth_msg (data->buffer, - data->username, - data->password, - &error); - data->offset = 0; + data->offset = 0; - if (data->length < 0) + if (!set_auth_msg (data->buffer, + data->username, + data->password, + &data->length, + &error)) { g_task_return_error (task, error); g_object_unref (task); @@ -873,13 +885,13 @@ send_connect_msg (GTask *task) g_free (data->buffer); data->buffer = g_malloc0 (SOCKS5_CONN_MSG_LEN); - data->length = set_connect_msg (data->buffer, - data->hostname, - data->port, - &error); data->offset = 0; - - if (data->length < 0) + + if (!set_connect_msg (data->buffer, + data->hostname, + data->port, + &data->length, + &error)) { g_task_return_error (task, error); g_object_unref (task); diff --git a/gio/gunixsocketaddress.c b/gio/gunixsocketaddress.c index 3d1a26e1e..0ba499aac 100644 --- a/gio/gunixsocketaddress.c +++ b/gio/gunixsocketaddress.c @@ -472,15 +472,21 @@ g_unix_socket_address_new_with_type (const gchar *path, { GSocketAddress *address; GByteArray *array; + size_t path_len_unsigned; if (type == G_UNIX_SOCKET_ADDRESS_ANONYMOUS) - path_len = 0; - else if (path_len == -1) - path_len = strlen (path); + path_len_unsigned = 0; + else if (path_len < 0) + path_len_unsigned = strlen (path); + else + path_len_unsigned = (size_t) path_len; - array = g_byte_array_sized_new (path_len); + /* The code below can’t handle anything longer. */ + g_return_val_if_fail (path_len_unsigned <= G_MAXUINT, NULL); - g_byte_array_append (array, (guint8 *)path, path_len); + array = g_byte_array_sized_new (path_len_unsigned); + + g_byte_array_append (array, (guint8 *)path, path_len_unsigned); address = g_object_new (G_TYPE_UNIX_SOCKET_ADDRESS, "path-as-array", array, diff --git a/gio/tests/data-output-stream.c b/gio/tests/data-output-stream.c index 0b324794d..1f52782a1 100644 --- a/gio/tests/data-output-stream.c +++ b/gio/tests/data-output-stream.c @@ -63,7 +63,7 @@ test_read_lines (GDataStreamNewlineType newline_type) GError *error = NULL; gpointer data; char *lines; - int size; + size_t size; int i; #define TEST_STRING "some_text" @@ -99,7 +99,7 @@ test_read_lines (GDataStreamNewlineType newline_type) /* compare data */ size = strlen (data); - g_assert_cmpint (size, <, MAX_LINES_BUFF); + g_assert_cmpuint (size, <, MAX_LINES_BUFF); g_assert_cmpstr ((char*)data, ==, lines); g_object_unref (base_stream); diff --git a/gio/tests/task.c b/gio/tests/task.c index a7f23125c..c9ae702a2 100644 --- a/gio/tests/task.c +++ b/gio/tests/task.c @@ -1470,7 +1470,7 @@ test_run_in_thread_overflow (void) GCancellable *cancellable; GTask *task; gchar buf[NUM_OVERFLOW_TASKS + 1]; - gint i; + size_t i; /* Queue way too many tasks and then sleep for a bit. The first 10 * tasks will be dispatched to threads and will then block on @@ -1516,13 +1516,13 @@ test_run_in_thread_overflow (void) * plausibly get (and we hope that if gtask is actually broken then * it will exceed those limits). */ - g_assert_cmpint (i, >=, 10); + g_assert_cmpuint (i, >=, 10); if (g_test_slow ()) - g_assert_cmpint (i, <, 50); + g_assert_cmpuint (i, <, 50); else - g_assert_cmpint (i, <, 20); + g_assert_cmpuint (i, <, 20); - g_assert_cmpint (i + strspn (buf + i, "X"), ==, NUM_OVERFLOW_TASKS); + g_assert_cmpuint (i + strspn (buf + i, "X"), ==, NUM_OVERFLOW_TASKS); } /* test_return_on_cancel */ diff --git a/gio/win32/gwin32fsmonitorutils.c b/gio/win32/gwin32fsmonitorutils.c index dd945dc87..d06dc458a 100644 --- a/gio/win32/gwin32fsmonitorutils.c +++ b/gio/win32/gwin32fsmonitorutils.c @@ -160,8 +160,8 @@ g_win32_fs_monitor_callback (DWORD error, if (monitor->isfile) { - gint long_filename_length = wcslen (monitor->wfilename_long); - gint short_filename_length = wcslen (monitor->wfilename_short); + size_t long_filename_length = wcslen (monitor->wfilename_long); + size_t short_filename_length = wcslen (monitor->wfilename_short); enum GWin32FileMonitorFileAlias alias_state; /* If monitoring a file, check that the changed file diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c index 605c28460..2e519b8f5 100644 --- a/gio/win32/gwinhttpfile.c +++ b/gio/win32/gwinhttpfile.c @@ -318,7 +318,7 @@ static const char * match_prefix (const char *path, const char *prefix) { - int prefix_len; + size_t prefix_len; prefix_len = strlen (prefix); if (strncmp (path, prefix, prefix_len) != 0) diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index ccc5aed37..d85106f65 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -223,12 +223,14 @@ gi_base_info_type_register_static (const char *type_name, { GTypeInfo info; + g_assert (instance_size <= G_MAXUINT16); + info.class_size = sizeof (GIBaseInfoClass); info.base_init = NULL; info.base_finalize = NULL; info.class_init = class_init; info.class_finalize = NULL; - info.instance_size = instance_size; + info.instance_size = (guint16) instance_size; info.n_preallocs = 0; info.instance_init = NULL; info.value_table = NULL; diff --git a/girepository/gicallableinfo.c b/girepository/gicallableinfo.c index 49430e9a8..23d31f1a4 100644 --- a/girepository/gicallableinfo.c +++ b/girepository/gicallableinfo.c @@ -651,7 +651,7 @@ gi_callable_info_invoke (GICallableInfo *info, GITypeInfo *rinfo; GITypeTag rtag; GIArgInfo *ainfo; - size_t n_args, n_invoke_args, in_pos, out_pos, i; + unsigned int n_args, n_invoke_args, in_pos, out_pos, i; void **args; gboolean success = FALSE; GError *local_error = NULL; diff --git a/girepository/gifieldinfo.c b/girepository/gifieldinfo.c index 819ccf72b..24b2a5e6d 100644 --- a/girepository/gifieldinfo.c +++ b/girepository/gifieldinfo.c @@ -190,7 +190,7 @@ gi_field_info_get_field (GIFieldInfo *field_info, void *mem, GIArgument *value) { - int offset; + size_t offset; GITypeInfo *type_info; gboolean result = FALSE; @@ -385,7 +385,7 @@ gi_field_info_set_field (GIFieldInfo *field_info, void *mem, const GIArgument *value) { - int offset; + size_t offset; GITypeInfo *type_info; gboolean result = FALSE; diff --git a/girepository/girnode.c b/girepository/girnode.c index efc022d72..b3ea89323 100644 --- a/girepository/girnode.c +++ b/girepository/girnode.c @@ -571,7 +571,7 @@ gi_ir_node_get_size (GIIrNode *node) g_assert (size <= G_MAXUINT32); - return size; + return (guint32) size; } static void diff --git a/girepository/girwriter.c b/girepository/girwriter.c index a0307a29d..d0b5d0803 100644 --- a/girepository/girwriter.c +++ b/girepository/girwriter.c @@ -1338,7 +1338,8 @@ gi_ir_writer_write (GIRepository *repository, gboolean show_all) { FILE *ofile; - size_t i, j; + size_t i; + unsigned int j; char **dependencies; Xml *xml; diff --git a/glib/gbase64.c b/glib/gbase64.c index 043593b05..2ea4a4ef4 100644 --- a/glib/gbase64.c +++ b/glib/gbase64.c @@ -424,7 +424,8 @@ guchar * g_base64_decode_inplace (gchar *text, gsize *out_len) { - gint input_length, state = 0; + gint state = 0; + size_t input_length; guint save = 0; g_return_val_if_fail (text != NULL, NULL); diff --git a/glib/gdate.c b/glib/gdate.c index c509bd303..c0d486c9d 100644 --- a/glib/gdate.c +++ b/glib/gdate.c @@ -2258,6 +2258,7 @@ win32_strftime_helper (const GDate *d, gchar *convbuf; glong convlen = 0; gsize retval; + size_t format_len = strlen (format); systemtime.wYear = tm->tm_year + 1900; systemtime.wMonth = tm->tm_mon + 1; @@ -2269,7 +2270,8 @@ win32_strftime_helper (const GDate *d, systemtime.wMilliseconds = 0; lcid = GetThreadLocale (); - result = g_array_sized_new (FALSE, FALSE, sizeof (wchar_t), MAX (128, strlen (format) * 2)); + result = g_array_sized_new (FALSE, FALSE, sizeof (wchar_t), + (format_len <= 64) ? (guint) format_len * 2 : 128); p = format; while (*p) diff --git a/glib/gdatetime.c b/glib/gdatetime.c index b5372d834..702a77c51 100644 --- a/glib/gdatetime.c +++ b/glib/gdatetime.c @@ -3268,7 +3268,7 @@ g_date_time_format_utf8 (GDateTime *datetime, GString *outstr, gboolean locale_is_utf8) { - guint len; + size_t len; guint colons; gunichar c; gboolean alt_digits = FALSE; diff --git a/glib/genviron.c b/glib/genviron.c index b72871b95..2b0136006 100644 --- a/glib/genviron.c +++ b/glib/genviron.c @@ -647,7 +647,7 @@ g_get_environ (void) { gunichar2 *strings; gchar **result; - gint i, n; + size_t i, n; strings = GetEnvironmentStringsW (); for (n = 0, i = 0; strings[n]; i++) diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 2801777e4..f40400ca5 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -373,7 +373,7 @@ g_file_test (const gchar *filename, { const gchar *lastdot = strrchr (filename, '.'); const gchar *pathext = NULL, *p; - int extlen; + size_t extlen; if (lastdot == NULL) break; @@ -401,7 +401,7 @@ g_file_test (const gchar *filename, const gchar *q = strchr (p, ';'); if (q == NULL) q = p + strlen (p); - if (extlen == q - p && + if (extlen == (size_t) (q - p) && memcmp (lastdot, p, extlen) == 0) { g_free ((gchar *) pathext); diff --git a/glib/gmessages.c b/glib/gmessages.c index f325a9196..2ce651a71 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -1420,9 +1420,9 @@ win32_is_pipe_tty (int fd) gboolean result = FALSE; HANDLE h_fd; FILE_NAME_INFO *info = NULL; - gint info_size = sizeof (FILE_NAME_INFO) + sizeof (WCHAR) * MAX_PATH; + size_t info_size = sizeof (FILE_NAME_INFO) + sizeof (WCHAR) * MAX_PATH; wchar_t *name = NULL; - gint length; + size_t length; h_fd = (HANDLE) _get_osfhandle (fd); diff --git a/glib/goption.c b/glib/goption.c index 530e0cdba..785b151f0 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -1461,7 +1461,7 @@ parse_long_option (GOptionContext *context, } else { - gint len = strlen (group->entries[j].long_name); + size_t len = strlen (group->entries[j].long_name); if (strncmp (arg, group->entries[j].long_name, len) == 0 && (arg[len] == '=' || arg[len] == 0)) diff --git a/glib/gpattern.c b/glib/gpattern.c index bf61da36f..f77e69b6b 100644 --- a/glib/gpattern.c +++ b/glib/gpattern.c @@ -65,9 +65,9 @@ typedef enum struct _GPatternSpec { GMatchType match_type; - guint pattern_length; - guint min_length; - guint max_length; + size_t pattern_length; + size_t min_length; + size_t max_length; gchar *pattern; }; diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 9af21a953..3688bea49 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -930,7 +930,7 @@ g_ascii_formatd (gchar *buffer, const char *decimal_point; gsize decimal_point_len; gchar *p; - int rest_len; + size_t rest_len; gchar format_char; g_return_val_if_fail (buffer != NULL, NULL); diff --git a/glib/gstring.c b/glib/gstring.c index 463bfeccc..bdd068344 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -134,7 +134,7 @@ g_string_new (const gchar *init) string = g_string_sized_new (2); else { - gint len; + size_t len; len = strlen (init); string = g_string_sized_new (len + 2); diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 5c5f9051f..253cfa7b3 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -3035,7 +3035,7 @@ static gboolean path_has_prefix (const char *path, const char *prefix) { - int prefix_len = strlen (prefix); + size_t prefix_len = strlen (prefix); return (strncmp (path, prefix, prefix_len) == 0 && (path[prefix_len] == '\0' || diff --git a/glib/gtranslit.c b/glib/gtranslit.c index c264241cc..85ffb1326 100644 --- a/glib/gtranslit.c +++ b/glib/gtranslit.c @@ -187,11 +187,11 @@ lookup_item_id_for_locale (const gchar *locale) { gchar key[MAX_LOCALE_NAME + 1]; const gchar *language; - guint language_len; + size_t language_len; const gchar *territory = NULL; - guint territory_len = 0; + size_t territory_len = 0; const gchar *modifier = NULL; - guint modifier_len = 0; + size_t modifier_len = 0; const gchar *next_char; guint id; diff --git a/glib/guniprop.c b/glib/guniprop.c index 61acad6e6..e147829e2 100644 --- a/glib/guniprop.c +++ b/glib/guniprop.c @@ -805,7 +805,7 @@ output_special_case (gchar *out_buffer, int which) { const gchar *p = special_case_table + offset; - gint len; + size_t len; if (type != G_UNICODE_TITLECASE_LETTER) p = g_utf8_next_char (p); diff --git a/glib/gutf8.c b/glib/gutf8.c index 5a875ce26..dd9966df5 100644 --- a/glib/gutf8.c +++ b/glib/gutf8.c @@ -1250,7 +1250,7 @@ g_utf16_to_ucs4 (const gunichar2 *str, const gunichar2 *in; gchar *out; gchar *result = NULL; - gint n_bytes; + size_t n_bytes; gunichar high_surrogate; g_return_val_if_fail (str != NULL, NULL); diff --git a/glib/gutils.c b/glib/gutils.c index 5eaa63845..057e2bcd7 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -196,7 +196,7 @@ g_find_program_in_path (const gchar *program) strchr (last_dot, '\\') != NULL || strchr (last_dot, '/') != NULL) { - const gint program_length = strlen (program); + const size_t program_length = strlen (program); gchar *pathext = g_build_path (";", ".exe;.cmd;.bat;.com", g_getenv ("PATHEXT"), diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c index 243a34f57..8bd16766c 100644 --- a/glib/gvariant-parser.c +++ b/glib/gvariant-parser.c @@ -327,10 +327,10 @@ static gboolean token_stream_peek_string (TokenStream *stream, const gchar *token) { - gint length = strlen (token); + size_t length = strlen (token); return token_stream_prepare (stream) && - stream->stream - stream->this == length && + (size_t) (stream->stream - stream->this) == length && memcmp (stream->this, token, length) == 0; } diff --git a/glib/tests/array-test.c b/glib/tests/array-test.c index 70f56e8a1..df9d15bdc 100644 --- a/glib/tests/array-test.c +++ b/glib/tests/array-test.c @@ -133,7 +133,7 @@ array_new_zero_terminated (void) garray = g_array_new (TRUE, FALSE, sizeof (gchar)); g_assert_cmpuint (garray->len, ==, 0); - g_array_append_vals (garray, "hello", strlen ("hello")); + g_array_append_vals (garray, "hello", (guint) strlen ("hello")); g_assert_cmpuint (garray->len, ==, 5); g_assert_cmpstr (garray->data, ==, "hello"); diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c index c24cd2f3e..27586be71 100644 --- a/glib/tests/gvariant.c +++ b/glib/tests/gvariant.c @@ -313,7 +313,7 @@ invalid_mutation (const gchar *type_string) /* else, perform a random mutation at a random point */ { - gint length, n; + size_t length, n; gchar *new; gchar p; diff --git a/glib/tests/pattern.c b/glib/tests/pattern.c index b590acb8a..414b86358 100644 --- a/glib/tests/pattern.c +++ b/glib/tests/pattern.c @@ -37,9 +37,9 @@ typedef enum struct _GPatternSpec { GMatchType match_type; - guint pattern_length; - guint min_length; - guint max_length; + size_t pattern_length; + size_t min_length; + size_t max_length; gchar *pattern; }; @@ -50,7 +50,7 @@ struct _CompileTest const gchar *src; GMatchType match_type; gchar *pattern; - guint min; + size_t min; }; static CompileTest compile_tests[] = { @@ -80,8 +80,8 @@ test_compilation (gconstpointer d) g_assert_cmpint (spec->match_type, ==, test->match_type); g_assert_cmpstr (spec->pattern, ==, test->pattern); - g_assert_cmpint (spec->pattern_length, ==, strlen (spec->pattern)); - g_assert_cmpint (spec->min_length, ==, test->min); + g_assert_cmpuint (spec->pattern_length, ==, strlen (spec->pattern)); + g_assert_cmpuint (spec->min_length, ==, test->min); g_pattern_spec_free (spec); } @@ -97,8 +97,8 @@ test_copy (gconstpointer d) g_assert_cmpint (p2->match_type, ==, test->match_type); g_assert_cmpstr (p2->pattern, ==, test->pattern); - g_assert_cmpint (p2->pattern_length, ==, strlen (p1->pattern)); - g_assert_cmpint (p2->min_length, ==, test->min); + g_assert_cmpuint (p2->pattern_length, ==, strlen (p1->pattern)); + g_assert_cmpuint (p2->min_length, ==, test->min); g_pattern_spec_free (p1); g_pattern_spec_free (p2); @@ -186,7 +186,8 @@ test_match (gconstpointer d) r = g_utf8_strreverse (test->string, -1); g_assert_cmpint (g_pattern_spec_match (p, strlen (test->string), test->string, r), ==, test->match); G_GNUC_BEGIN_IGNORE_DEPRECATIONS - g_assert_cmpint (g_pattern_match (p, strlen (test->string), test->string, r), ==, test->match); + g_assert_cmpuint (strlen (test->string), <=, G_MAXUINT); + g_assert_cmpint (g_pattern_match (p, (guint) strlen (test->string), test->string, r), ==, test->match); G_GNUC_END_IGNORE_DEPRECATIONS g_free (r); diff --git a/glib/tests/scannerapi.c b/glib/tests/scannerapi.c index cee3956ea..715dd14d3 100644 --- a/glib/tests/scannerapi.c +++ b/glib/tests/scannerapi.c @@ -111,7 +111,7 @@ test_scanner_tokens (ScannerFixture *fix, gconstpointer test_data) { gchar buf[] = "(\t\n\r\\){}"; - const gint buflen = strlen (buf); + const size_t buflen = strlen (buf); gchar tokbuf[] = "(\\){}"; const gsize tokbuflen = strlen (tokbuf); gsize i; diff --git a/glib/tests/spawn-test-win32-gui.c b/glib/tests/spawn-test-win32-gui.c index 46353c8f3..a84fe83ff 100644 --- a/glib/tests/spawn-test-win32-gui.c +++ b/glib/tests/spawn-test-win32-gui.c @@ -36,7 +36,8 @@ WinMain (struct HINSTANCE__ *hInstance, { int infd = atoi (__argv[2]); int outfd = atoi (__argv[3]); - int k, n; + SSIZE_T k; + size_t n; char buf[100] = {0}; if (infd < 0 || outfd < 0) @@ -55,22 +56,28 @@ WinMain (struct HINSTANCE__ *hInstance, exit (1); } - if ((k = read (infd, &n, sizeof (n))) != sizeof (n)) + k = read (infd, &n, sizeof (n)); + if (k < 0 || (size_t) k != sizeof (n)) { - fprintf (stderr, "spawn-test-win32-gui: Got only %d bytes, wanted %d\n", - k, (int)sizeof (n)); + int errsv = errno; + if (k < 0) + fprintf (stderr, "spawn-test-win32-gui: Read error: %s\n", strerror (errsv)); + else + fprintf (stderr, "spawn-test-win32-gui: Got only %zu bytes, wanted %zu\n", + (size_t) k, sizeof (n)); exit (1); } - fprintf (stderr, "spawn-test-win32-gui: Parent says %d bytes to read\n", n); + fprintf (stderr, "spawn-test-win32-gui: Parent says %zu bytes to read\n", n); - if ((k = read (infd, buf, n)) != n) + k = read (infd, buf, n); + if (k < 0 || (size_t) k != n) { int errsv = errno; - if (k == -1) + if (k < 0) fprintf (stderr, "spawn-test-win32-gui: Read error: %s\n", strerror (errsv)); else - fprintf (stderr, "spawn-test-win32-gui: Got only %d bytes\n", k); + fprintf (stderr, "spawn-test-win32-gui: Got only %zu bytes\n", (size_t) k); exit (1); } diff --git a/glib/tests/spawn-test.c b/glib/tests/spawn-test.c index fdc35e86f..779645a13 100644 --- a/glib/tests/spawn-test.c +++ b/glib/tests/spawn-test.c @@ -198,7 +198,7 @@ test_spawn_basics (void) gchar *output = NULL; gchar *erroutput = NULL; #ifdef G_OS_WIN32 - int n; + size_t n; char buf[100]; int pipedown[2], pipeup[2]; gchar **argv = NULL; diff --git a/glib/tests/tree.c b/glib/tests/tree.c index 055a2c266..6e7fc0b5a 100644 --- a/glib/tests/tree.c +++ b/glib/tests/tree.c @@ -455,7 +455,7 @@ test_tree_insert (void) { GTree *tree; gchar *p; - gint i; + size_t i; gchar *scrambled; tree = g_tree_new (my_compare); @@ -468,8 +468,8 @@ test_tree_insert (void) g_tree_unref (tree); tree = g_tree_new (my_compare); - for (i = strlen (chars) - 1; i >= 0; i--) - g_tree_insert (tree, &chars[i], &chars[i]); + for (i = strlen (chars); i > 0; i--) + g_tree_insert (tree, &chars[i - 1], &chars[i - 1]); p = chars; g_tree_foreach (tree, check_order, &p); diff --git a/gmodule/gmodule-win32.c b/gmodule/gmodule-win32.c index bea841271..5748bef0f 100644 --- a/gmodule/gmodule-win32.c +++ b/gmodule/gmodule-win32.c @@ -205,7 +205,7 @@ static gchar* _g_module_build_path (const gchar *directory, const gchar *module_name) { - gint k; + size_t k; k = strlen (module_name); diff --git a/gobject/gobject-query.c b/gobject/gobject-query.c index 76670320f..1cdff2ac6 100644 --- a/gobject/gobject-query.c +++ b/gobject/gobject-query.c @@ -47,7 +47,7 @@ show_nodes (GType type, const gchar *indent) { GType *children; - guint i; + size_t i; if (!type) return; diff --git a/gobject/gtype.c b/gobject/gtype.c index 8222fc493..b8e724092 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -1073,7 +1073,7 @@ type_data_make_W (TypeNode *node, { TypeData *data; GTypeValueTable *vtable = NULL; - guint vtable_size = 0; + size_t vtable_size = 0; g_assert (node->data == NULL && info != NULL);