Merge branch 'fix-warnings-glib' into 'master'

Fix warnings glib

See merge request GNOME/glib!680
This commit is contained in:
Philip Withnall 2019-03-19 11:02:38 +00:00
commit c8692fffe0
25 changed files with 201 additions and 149 deletions

View File

@ -246,7 +246,7 @@
struct _GHashTable struct _GHashTable
{ {
gint size; gsize size;
gint mod; gint mod;
guint mask; guint mask;
gint nnodes; gint nnodes;
@ -279,9 +279,9 @@ typedef struct
GHashTable *hash_table; GHashTable *hash_table;
gpointer dummy1; gpointer dummy1;
gpointer dummy2; gpointer dummy2;
int position; gint position;
gboolean dummy3; gboolean dummy3;
int version; gint version;
} RealIter; } RealIter;
G_STATIC_ASSERT (sizeof (GHashTableIter) == sizeof (RealIter)); G_STATIC_ASSERT (sizeof (GHashTableIter) == sizeof (RealIter));
@ -798,7 +798,7 @@ static void
g_hash_table_resize (GHashTable *hash_table) g_hash_table_resize (GHashTable *hash_table)
{ {
guint32 *reallocated_buckets_bitmap; guint32 *reallocated_buckets_bitmap;
guint old_size; gsize old_size;
gboolean is_a_set; gboolean is_a_set;
old_size = hash_table->size; old_size = hash_table->size;
@ -1105,14 +1105,14 @@ g_hash_table_iter_next (GHashTableIter *iter,
#ifndef G_DISABLE_ASSERT #ifndef G_DISABLE_ASSERT
g_return_val_if_fail (ri->version == ri->hash_table->version, FALSE); g_return_val_if_fail (ri->version == ri->hash_table->version, FALSE);
#endif #endif
g_return_val_if_fail (ri->position < ri->hash_table->size, FALSE); g_return_val_if_fail (ri->position < (gssize) ri->hash_table->size, FALSE);
position = ri->position; position = ri->position;
do do
{ {
position++; position++;
if (position >= ri->hash_table->size) if (position >= (gssize) ri->hash_table->size)
{ {
ri->position = position; ri->position = position;
return FALSE; return FALSE;
@ -1155,7 +1155,7 @@ iter_remove_or_steal (RealIter *ri, gboolean notify)
g_return_if_fail (ri->version == ri->hash_table->version); g_return_if_fail (ri->version == ri->hash_table->version);
#endif #endif
g_return_if_fail (ri->position >= 0); g_return_if_fail (ri->position >= 0);
g_return_if_fail (ri->position < ri->hash_table->size); g_return_if_fail ((gsize) ri->position < ri->hash_table->size);
g_hash_table_remove_node (ri->hash_table, ri->position, notify); g_hash_table_remove_node (ri->hash_table, ri->position, notify);
@ -1339,7 +1339,7 @@ g_hash_table_iter_replace (GHashTableIter *iter,
g_return_if_fail (ri->version == ri->hash_table->version); g_return_if_fail (ri->version == ri->hash_table->version);
#endif #endif
g_return_if_fail (ri->position >= 0); g_return_if_fail (ri->position >= 0);
g_return_if_fail (ri->position < ri->hash_table->size); g_return_if_fail ((gsize) ri->position < ri->hash_table->size);
node_hash = ri->hash_table->hashes[ri->position]; node_hash = ri->hash_table->hashes[ri->position];
@ -1880,7 +1880,7 @@ g_hash_table_foreach_remove_or_steal (GHashTable *hash_table,
gboolean notify) gboolean notify)
{ {
guint deleted = 0; guint deleted = 0;
gint i; gsize i;
#ifndef G_DISABLE_ASSERT #ifndef G_DISABLE_ASSERT
gint version = hash_table->version; gint version = hash_table->version;
#endif #endif
@ -1989,7 +1989,7 @@ g_hash_table_foreach (GHashTable *hash_table,
GHFunc func, GHFunc func,
gpointer user_data) gpointer user_data)
{ {
gint i; gsize i;
#ifndef G_DISABLE_ASSERT #ifndef G_DISABLE_ASSERT
gint version; gint version;
#endif #endif
@ -2047,7 +2047,7 @@ g_hash_table_find (GHashTable *hash_table,
GHRFunc predicate, GHRFunc predicate,
gpointer user_data) gpointer user_data)
{ {
gint i; gsize i;
#ifndef G_DISABLE_ASSERT #ifndef G_DISABLE_ASSERT
gint version; gint version;
#endif #endif
@ -2119,7 +2119,7 @@ g_hash_table_size (GHashTable *hash_table)
GList * GList *
g_hash_table_get_keys (GHashTable *hash_table) g_hash_table_get_keys (GHashTable *hash_table)
{ {
gint i; gsize i;
GList *retval; GList *retval;
g_return_val_if_fail (hash_table != NULL, NULL); g_return_val_if_fail (hash_table != NULL, NULL);
@ -2167,7 +2167,7 @@ g_hash_table_get_keys_as_array (GHashTable *hash_table,
guint *length) guint *length)
{ {
gpointer *result; gpointer *result;
guint i, j = 0; gsize i, j = 0;
result = g_new (gpointer, hash_table->nnodes + 1); result = g_new (gpointer, hash_table->nnodes + 1);
for (i = 0; i < hash_table->size; i++) for (i = 0; i < hash_table->size; i++)
@ -2205,7 +2205,7 @@ g_hash_table_get_keys_as_array (GHashTable *hash_table,
GList * GList *
g_hash_table_get_values (GHashTable *hash_table) g_hash_table_get_values (GHashTable *hash_table)
{ {
gint i; gsize i;
GList *retval; GList *retval;
g_return_val_if_fail (hash_table != NULL, NULL); g_return_val_if_fail (hash_table != NULL, NULL);

View File

@ -2180,6 +2180,7 @@ g_io_channel_write_chars (GIOChannel *channel,
gsize *bytes_written, gsize *bytes_written,
GError **error) GError **error)
{ {
gsize count_unsigned;
GIOStatus status; GIOStatus status;
gssize wrote_bytes = 0; gssize wrote_bytes = 0;
@ -2190,8 +2191,9 @@ g_io_channel_write_chars (GIOChannel *channel,
if ((count < 0) && buf) if ((count < 0) && buf)
count = strlen (buf); count = strlen (buf);
count_unsigned = count;
if (count == 0)
if (count_unsigned == 0)
{ {
if (bytes_written) if (bytes_written)
*bytes_written = 0; *bytes_written = 0;
@ -2199,7 +2201,7 @@ g_io_channel_write_chars (GIOChannel *channel,
} }
g_return_val_if_fail (buf != NULL, G_IO_STATUS_ERROR); g_return_val_if_fail (buf != NULL, G_IO_STATUS_ERROR);
g_return_val_if_fail (count > 0, G_IO_STATUS_ERROR); g_return_val_if_fail (count_unsigned > 0, G_IO_STATUS_ERROR);
/* Raw write case */ /* Raw write case */
@ -2210,7 +2212,8 @@ g_io_channel_write_chars (GIOChannel *channel,
g_assert (!channel->write_buf || channel->write_buf->len == 0); g_assert (!channel->write_buf || channel->write_buf->len == 0);
g_assert (channel->partial_write_buf[0] == '\0'); g_assert (channel->partial_write_buf[0] == '\0');
status = channel->funcs->io_write (channel, buf, count, &tmp_bytes, error); status = channel->funcs->io_write (channel, buf, count_unsigned,
&tmp_bytes, error);
if (bytes_written) if (bytes_written)
*bytes_written = tmp_bytes; *bytes_written = tmp_bytes;
@ -2286,7 +2289,7 @@ g_io_channel_write_chars (GIOChannel *channel,
if (!channel->encoding) if (!channel->encoding)
{ {
gssize write_this = MIN (space_in_buf, count - wrote_bytes); gssize write_this = MIN (space_in_buf, count_unsigned - wrote_bytes);
g_string_append_len (channel->write_buf, buf, write_this); g_string_append_len (channel->write_buf, buf, write_this);
buf += write_this; buf += write_this;
@ -2306,7 +2309,7 @@ g_io_channel_write_chars (GIOChannel *channel,
from_buf = channel->partial_write_buf; from_buf = channel->partial_write_buf;
from_buf_old_len = strlen (channel->partial_write_buf); from_buf_old_len = strlen (channel->partial_write_buf);
g_assert (from_buf_old_len > 0); g_assert (from_buf_old_len > 0);
from_buf_len = MIN (6, from_buf_old_len + count); from_buf_len = MIN (6, from_buf_old_len + count_unsigned);
memcpy (channel->partial_write_buf + from_buf_old_len, buf, memcpy (channel->partial_write_buf + from_buf_old_len, buf,
from_buf_len - from_buf_old_len); from_buf_len - from_buf_old_len);
@ -2314,7 +2317,7 @@ g_io_channel_write_chars (GIOChannel *channel,
else else
{ {
from_buf = buf; from_buf = buf;
from_buf_len = count - wrote_bytes; from_buf_len = count_unsigned - wrote_bytes;
from_buf_old_len = 0; from_buf_old_len = 0;
} }
@ -2404,7 +2407,7 @@ reconvert:
memcpy (channel->partial_write_buf, from_buf, left_len); memcpy (channel->partial_write_buf, from_buf, left_len);
channel->partial_write_buf[left_len] = '\0'; channel->partial_write_buf[left_len] = '\0';
if (bytes_written) if (bytes_written)
*bytes_written = count; *bytes_written = count_unsigned;
return G_IO_STATUS_NORMAL; return G_IO_STATUS_NORMAL;
} }
@ -2416,12 +2419,12 @@ reconvert:
* less than a full character * less than a full character
*/ */
g_assert (count == from_buf_len - from_buf_old_len); g_assert (count_unsigned == from_buf_len - from_buf_old_len);
channel->partial_write_buf[from_buf_len] = '\0'; channel->partial_write_buf[from_buf_len] = '\0';
if (bytes_written) if (bytes_written)
*bytes_written = count; *bytes_written = count_unsigned;
return G_IO_STATUS_NORMAL; return G_IO_STATUS_NORMAL;
} }
@ -2483,7 +2486,7 @@ reconvert:
} }
if (bytes_written) if (bytes_written)
*bytes_written = count; *bytes_written = count_unsigned;
return G_IO_STATUS_NORMAL; return G_IO_STATUS_NORMAL;
} }

View File

@ -107,7 +107,8 @@ GSourceFuncs g_io_watch_funcs = {
g_io_unix_prepare, g_io_unix_prepare,
g_io_unix_check, g_io_unix_check,
g_io_unix_dispatch, g_io_unix_dispatch,
g_io_unix_finalize g_io_unix_finalize,
NULL, NULL
}; };
static GIOFuncs unix_channel_funcs = { static GIOFuncs unix_channel_funcs = {

View File

@ -310,7 +310,7 @@ g_unix_fd_source_dispatch (GSource *source,
} }
GSourceFuncs g_unix_fd_source_funcs = { GSourceFuncs g_unix_fd_source_funcs = {
NULL, NULL, g_unix_fd_source_dispatch, NULL NULL, NULL, g_unix_fd_source_dispatch, NULL, NULL, NULL
}; };
/** /**

View File

@ -476,7 +476,8 @@ GSourceFuncs g_unix_signal_funcs =
g_unix_signal_watch_prepare, g_unix_signal_watch_prepare,
g_unix_signal_watch_check, g_unix_signal_watch_check,
g_unix_signal_watch_dispatch, g_unix_signal_watch_dispatch,
g_unix_signal_watch_finalize g_unix_signal_watch_finalize,
NULL, NULL
}; };
#endif /* !G_OS_WIN32 */ #endif /* !G_OS_WIN32 */
G_LOCK_DEFINE_STATIC (main_context_list); G_LOCK_DEFINE_STATIC (main_context_list);
@ -487,7 +488,7 @@ GSourceFuncs g_timeout_funcs =
NULL, /* prepare */ NULL, /* prepare */
NULL, /* check */ NULL, /* check */
g_timeout_dispatch, g_timeout_dispatch,
NULL NULL, NULL, NULL
}; };
GSourceFuncs g_child_watch_funcs = GSourceFuncs g_child_watch_funcs =
@ -495,7 +496,8 @@ GSourceFuncs g_child_watch_funcs =
g_child_watch_prepare, g_child_watch_prepare,
g_child_watch_check, g_child_watch_check,
g_child_watch_dispatch, g_child_watch_dispatch,
g_child_watch_finalize g_child_watch_finalize,
NULL, NULL
}; };
GSourceFuncs g_idle_funcs = GSourceFuncs g_idle_funcs =
@ -503,7 +505,7 @@ GSourceFuncs g_idle_funcs =
g_idle_prepare, g_idle_prepare,
g_idle_check, g_idle_check,
g_idle_dispatch, g_idle_dispatch,
NULL NULL, NULL, NULL
}; };
/** /**
@ -1609,10 +1611,12 @@ g_source_set_callback_indirect (GSource *source,
LOCK_CONTEXT (context); LOCK_CONTEXT (context);
if (callback_funcs != &g_source_callback_funcs) if (callback_funcs != &g_source_callback_funcs)
TRACE (GLIB_SOURCE_SET_CALLBACK_INDIRECT (source, callback_data, {
callback_funcs->ref, TRACE (GLIB_SOURCE_SET_CALLBACK_INDIRECT (source, callback_data,
callback_funcs->unref, callback_funcs->ref,
callback_funcs->get)); callback_funcs->unref,
callback_funcs->get));
}
old_cb_data = source->callback_data; old_cb_data = source->callback_data;
old_cb_funcs = source->callback_funcs; old_cb_funcs = source->callback_funcs;

View File

@ -150,7 +150,7 @@ mapped_file_new_from_fd (int fd,
file->contents = MAP_FAILED; file->contents = MAP_FAILED;
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
if (st.st_size > G_MAXSIZE) if (sizeof (st.st_size) > sizeof (gsize) && st.st_size > (off_t) G_MAXSIZE)
{ {
errno = EINVAL; errno = EINVAL;
} }

View File

@ -786,8 +786,8 @@ unescape_gstring_inplace (GMarkupParseContext *context,
} }
} }
g_assert (to - string->str <= string->len); g_assert (to - string->str <= (gssize) string->len);
if (to - string->str != string->len) if (to - string->str != (gssize) string->len)
g_string_truncate (string, to - string->str); g_string_truncate (string, to - string->str);
*is_ascii = !(mask & 0x80); *is_ascii = !(mask & 0x80);
@ -2629,7 +2629,7 @@ g_markup_parse_boolean (const char *string,
{ {
char const * const falses[] = { "false", "f", "no", "n", "0" }; char const * const falses[] = { "false", "f", "no", "n", "0" };
char const * const trues[] = { "true", "t", "yes", "y", "1" }; char const * const trues[] = { "true", "t", "yes", "y", "1" };
int i; gsize i;
for (i = 0; i < G_N_ELEMENTS (falses); i++) for (i = 0; i < G_N_ELEMENTS (falses); i++)
{ {

View File

@ -277,7 +277,7 @@ struct _GOptionGroup
gpointer translate_data; gpointer translate_data;
GOptionEntry *entries; GOptionEntry *entries;
gint n_entries; gsize n_entries;
GOptionParseFunc pre_parse_func; GOptionParseFunc pre_parse_func;
GOptionParseFunc post_parse_func; GOptionParseFunc post_parse_func;
@ -665,7 +665,7 @@ calculate_max_length (GOptionGroup *group,
GHashTable *aliases) GHashTable *aliases)
{ {
GOptionEntry *entry; GOptionEntry *entry;
gint i, len, max_length; gsize i, len, max_length;
const gchar *long_name; const gchar *long_name;
max_length = 0; max_length = 0;
@ -828,7 +828,7 @@ g_option_context_get_help (GOptionContext *context,
{ {
GList *list; GList *list;
gint max_length = 0, len; gint max_length = 0, len;
gint i; gsize i;
GOptionEntry *entry; GOptionEntry *entry;
GHashTable *shadow_map; GHashTable *shadow_map;
GHashTable *aliases; GHashTable *aliases;
@ -1505,7 +1505,7 @@ parse_short_option (GOptionContext *context,
GError **error, GError **error,
gboolean *parsed) gboolean *parsed)
{ {
gint j; gsize j;
for (j = 0; j < group->n_entries; j++) for (j = 0; j < group->n_entries; j++)
{ {
@ -1587,7 +1587,7 @@ parse_long_option (GOptionContext *context,
GError **error, GError **error,
gboolean *parsed) gboolean *parsed)
{ {
gint j; gsize j;
for (j = 0; j < group->n_entries; j++) for (j = 0; j < group->n_entries; j++)
{ {
@ -1698,7 +1698,7 @@ parse_remaining_arg (GOptionContext *context,
GError **error, GError **error,
gboolean *parsed) gboolean *parsed)
{ {
gint j; gsize j;
for (j = 0; j < group->n_entries; j++) for (j = 0; j < group->n_entries; j++)
{ {
@ -2353,7 +2353,7 @@ void
g_option_group_add_entries (GOptionGroup *group, g_option_group_add_entries (GOptionGroup *group,
const GOptionEntry *entries) const GOptionEntry *entries)
{ {
gint i, n_entries; gsize i, n_entries;
g_return_if_fail (entries != NULL); g_return_if_fail (entries != NULL);

View File

@ -86,7 +86,7 @@ static const guint g_primes[] =
guint guint
g_spaced_primes_closest (guint num) g_spaced_primes_closest (guint num)
{ {
gint i; gsize i;
for (i = 0; i < G_N_ELEMENTS (g_primes); i++) for (i = 0; i < G_N_ELEMENTS (g_primes); i++)
if (g_primes[i] > num) if (g_primes[i] > num)

View File

@ -271,7 +271,7 @@ g_quark_to_string (GQuark quark)
{ {
gchar* result = NULL; gchar* result = NULL;
gchar **strings; gchar **strings;
gint seq_id; guint seq_id;
seq_id = g_atomic_int_get (&quark_seq_id); seq_id = g_atomic_int_get (&quark_seq_id);
strings = g_atomic_pointer_get (&quarks); strings = g_atomic_pointer_get (&quarks);

View File

@ -341,6 +341,7 @@ static const GScannerConfig g_scanner_config_template =
FALSE /* symbol_2_token */, FALSE /* symbol_2_token */,
FALSE /* scope_0_fallback */, FALSE /* scope_0_fallback */,
FALSE /* store_int64 */, FALSE /* store_int64 */,
0 /* padding_dummy */
}; };

View File

@ -640,7 +640,10 @@ magazine_cache_trim (Allocator *allocator,
/* trim magazine cache from tail */ /* trim magazine cache from tail */
ChunkLink *current = magazine_chain_prev (allocator->magazines[ix]); ChunkLink *current = magazine_chain_prev (allocator->magazines[ix]);
ChunkLink *trash = NULL; ChunkLink *trash = NULL;
while (ABS (stamp - magazine_chain_uint_stamp (current)) >= allocator->config.working_set_msecs) while ((stamp >= magazine_chain_uint_stamp (current) &&
stamp - magazine_chain_uint_stamp (current) >= allocator->config.working_set_msecs) ||
(stamp <= magazine_chain_uint_stamp (current) &&
magazine_chain_uint_stamp (current) - stamp >= allocator->config.working_set_msecs))
{ {
/* unlink */ /* unlink */
ChunkLink *prev = magazine_chain_prev (current); ChunkLink *prev = magazine_chain_prev (current);

View File

@ -2700,13 +2700,14 @@ g_strstr_len (const gchar *haystack,
{ {
const gchar *p = haystack; const gchar *p = haystack;
gsize needle_len = strlen (needle); gsize needle_len = strlen (needle);
gsize haystack_len_unsigned = haystack_len;
const gchar *end; const gchar *end;
gsize i; gsize i;
if (needle_len == 0) if (needle_len == 0)
return (gchar *)haystack; return (gchar *)haystack;
if (haystack_len < needle_len) if (haystack_len_unsigned < needle_len)
return NULL; return NULL;
end = haystack + haystack_len - needle_len; end = haystack + haystack_len - needle_len;

View File

@ -428,6 +428,8 @@ g_string_insert_len (GString *string,
const gchar *val, const gchar *val,
gssize len) gssize len)
{ {
gsize len_unsigned, pos_unsigned;
g_return_val_if_fail (string != NULL, NULL); g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (len == 0 || val != NULL, string); g_return_val_if_fail (len == 0 || val != NULL, string);
@ -436,11 +438,15 @@ g_string_insert_len (GString *string,
if (len < 0) if (len < 0)
len = strlen (val); len = strlen (val);
len_unsigned = len;
if (pos < 0) if (pos < 0)
pos = string->len; pos_unsigned = string->len;
else else
g_return_val_if_fail (pos <= string->len, string); {
pos_unsigned = pos;
g_return_val_if_fail (pos_unsigned <= string->len, string);
}
/* Check whether val represents a substring of string. /* Check whether val represents a substring of string.
* This test probably violates chapter and verse of the C standards, * This test probably violates chapter and verse of the C standards,
@ -452,45 +458,48 @@ g_string_insert_len (GString *string,
gsize offset = val - string->str; gsize offset = val - string->str;
gsize precount = 0; gsize precount = 0;
g_string_maybe_expand (string, len); g_string_maybe_expand (string, len_unsigned);
val = string->str + offset; val = string->str + offset;
/* At this point, val is valid again. */ /* At this point, val is valid again. */
/* Open up space where we are going to insert. */ /* Open up space where we are going to insert. */
if (pos < string->len) if (pos_unsigned < string->len)
memmove (string->str + pos + len, string->str + pos, string->len - pos); memmove (string->str + pos_unsigned + len_unsigned,
string->str + pos_unsigned, string->len - pos_unsigned);
/* Move the source part before the gap, if any. */ /* Move the source part before the gap, if any. */
if (offset < pos) if (offset < pos_unsigned)
{ {
precount = MIN (len, pos - offset); precount = MIN (len_unsigned, pos_unsigned - offset);
memcpy (string->str + pos, val, precount); memcpy (string->str + pos_unsigned, val, precount);
} }
/* Move the source part after the gap, if any. */ /* Move the source part after the gap, if any. */
if (len > precount) if (len_unsigned > precount)
memcpy (string->str + pos + precount, memcpy (string->str + pos_unsigned + precount,
val + /* Already moved: */ precount + /* Space opened up: */ len, val + /* Already moved: */ precount +
len - precount); /* Space opened up: */ len_unsigned,
len_unsigned - precount);
} }
else else
{ {
g_string_maybe_expand (string, len); g_string_maybe_expand (string, len_unsigned);
/* If we aren't appending at the end, move a hunk /* If we aren't appending at the end, move a hunk
* of the old string to the end, opening up space * of the old string to the end, opening up space
*/ */
if (pos < string->len) if (pos_unsigned < string->len)
memmove (string->str + pos + len, string->str + pos, string->len - pos); memmove (string->str + pos_unsigned + len_unsigned,
string->str + pos_unsigned, string->len - pos_unsigned);
/* insert the new string */ /* insert the new string */
if (len == 1) if (len_unsigned == 1)
string->str[pos] = *val; string->str[pos_unsigned] = *val;
else else
memcpy (string->str + pos, val, len); memcpy (string->str + pos_unsigned, val, len_unsigned);
} }
string->len += len; string->len += len_unsigned;
string->str[string->len] = 0; string->str[string->len] = 0;
@ -778,6 +787,8 @@ g_string_insert_c (GString *string,
gssize pos, gssize pos,
gchar c) gchar c)
{ {
gsize pos_unsigned;
g_return_val_if_fail (string != NULL, NULL); g_return_val_if_fail (string != NULL, NULL);
g_string_maybe_expand (string, 1); g_string_maybe_expand (string, 1);
@ -785,13 +796,15 @@ g_string_insert_c (GString *string,
if (pos < 0) if (pos < 0)
pos = string->len; pos = string->len;
else else
g_return_val_if_fail (pos <= string->len, string); g_return_val_if_fail ((gsize) pos <= string->len, string);
pos_unsigned = pos;
/* If not just an append, move the old stuff */ /* If not just an append, move the old stuff */
if (pos < string->len) if (pos_unsigned < string->len)
memmove (string->str + pos + 1, string->str + pos, string->len - pos); memmove (string->str + pos_unsigned + 1,
string->str + pos_unsigned, string->len - pos_unsigned);
string->str[pos] = c; string->str[pos_unsigned] = c;
string->len += 1; string->len += 1;
@ -860,10 +873,10 @@ g_string_insert_unichar (GString *string,
if (pos < 0) if (pos < 0)
pos = string->len; pos = string->len;
else else
g_return_val_if_fail (pos <= string->len, string); g_return_val_if_fail ((gsize) pos <= string->len, string);
/* If not just an append, move the old stuff */ /* If not just an append, move the old stuff */
if (pos < string->len) if ((gsize) pos < string->len)
memmove (string->str + pos + charlen, string->str + pos, string->len - pos); memmove (string->str + pos + charlen, string->str + pos, string->len - pos);
dest = string->str + pos; dest = string->str + pos;
@ -970,21 +983,28 @@ g_string_erase (GString *string,
gssize pos, gssize pos,
gssize len) gssize len)
{ {
gsize len_unsigned, pos_unsigned;
g_return_val_if_fail (string != NULL, NULL); g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (pos >= 0, string); g_return_val_if_fail (pos >= 0, string);
g_return_val_if_fail (pos <= string->len, string); pos_unsigned = pos;
g_return_val_if_fail (pos_unsigned <= string->len, string);
if (len < 0) if (len < 0)
len = string->len - pos; len_unsigned = string->len - pos_unsigned;
else else
{ {
g_return_val_if_fail (pos + len <= string->len, string); len_unsigned = len;
g_return_val_if_fail (pos_unsigned + len_unsigned <= string->len, string);
if (pos + len < string->len) if (pos_unsigned + len_unsigned < string->len)
memmove (string->str + pos, string->str + pos + len, string->len - (pos + len)); memmove (string->str + pos_unsigned,
string->str + pos_unsigned + len_unsigned,
string->len - (pos_unsigned + len_unsigned));
} }
string->len -= len; string->len -= len_unsigned;
string->str[string->len] = 0; string->str[string->len] = 0;

View File

@ -677,7 +677,7 @@ int
main (int argc, main (int argc,
char **argv) char **argv)
{ {
guint ui; gint ui;
g_set_prgname (argv[0]); g_set_prgname (argv[0]);
parse_args (&argc, &argv); parse_args (&argc, &argv);

View File

@ -3829,7 +3829,7 @@ g_test_build_filename_va (GTestFileType file_type,
va_list ap) va_list ap)
{ {
const gchar *pathv[16]; const gchar *pathv[16];
gint num_path_segments; gsize num_path_segments;
if (file_type == G_TEST_DIST) if (file_type == G_TEST_DIST)
pathv[0] = test_disted_files_dir; pathv[0] = test_disted_files_dir;

View File

@ -1177,7 +1177,7 @@ g_system_thread_new (GThreadFunc proxy,
#ifdef _SC_THREAD_STACK_MIN #ifdef _SC_THREAD_STACK_MIN
long min_stack_size = sysconf (_SC_THREAD_STACK_MIN); long min_stack_size = sysconf (_SC_THREAD_STACK_MIN);
if (min_stack_size >= 0) if (min_stack_size >= 0)
stack_size = MAX (min_stack_size, stack_size); stack_size = MAX ((gulong) min_stack_size, stack_size);
#endif /* _SC_THREAD_STACK_MIN */ #endif /* _SC_THREAD_STACK_MIN */
/* No error check here, because some systems can't do it and /* No error check here, because some systems can't do it and
* we simply don't want threads to fail because of that. */ * we simply don't want threads to fail because of that. */

View File

@ -91,7 +91,7 @@ struct _GRealThreadPool
GAsyncQueue *queue; GAsyncQueue *queue;
GCond cond; GCond cond;
gint max_threads; gint max_threads;
gint num_threads; guint num_threads;
gboolean running; gboolean running;
gboolean immediate; gboolean immediate;
gboolean waiting; gboolean waiting;
@ -154,7 +154,7 @@ g_thread_pool_wait_for_new_pool (void)
do do
{ {
if (g_atomic_int_get (&unused_threads) >= local_max_unused_threads) if ((guint) g_atomic_int_get (&unused_threads) >= local_max_unused_threads)
{ {
/* If this is a superfluous thread, stop it. */ /* If this is a superfluous thread, stop it. */
pool = NULL; pool = NULL;
@ -234,7 +234,7 @@ g_thread_pool_wait_for_new_task (GRealThreadPool *pool)
g_async_queue_length_unlocked (pool->queue) > 0)) g_async_queue_length_unlocked (pool->queue) > 0))
{ {
/* This thread pool is still active. */ /* This thread pool is still active. */
if (pool->num_threads > pool->max_threads && pool->max_threads != -1) if (pool->max_threads != -1 && pool->num_threads > (guint) pool->max_threads)
{ {
/* This is a superfluous thread, so it goes to the global pool. */ /* This is a superfluous thread, so it goes to the global pool. */
DEBUG_MSG (("superfluous thread %p in pool %p.", DEBUG_MSG (("superfluous thread %p in pool %p.",
@ -340,7 +340,7 @@ g_thread_pool_thread_proxy (gpointer data)
* queue, wakeup the remaining threads. * queue, wakeup the remaining threads.
*/ */
if (g_async_queue_length_unlocked (pool->queue) == if (g_async_queue_length_unlocked (pool->queue) ==
- pool->num_threads) (gint) -pool->num_threads)
g_thread_pool_wakeup_and_stop_all (pool); g_thread_pool_wakeup_and_stop_all (pool);
} }
} }
@ -386,7 +386,7 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
{ {
gboolean success = FALSE; gboolean success = FALSE;
if (pool->num_threads >= pool->max_threads && pool->max_threads != -1) if (pool->max_threads != -1 && pool->num_threads >= (guint) pool->max_threads)
/* Enough threads are already running */ /* Enough threads are already running */
return TRUE; return TRUE;
@ -504,7 +504,7 @@ g_thread_pool_new (GFunc func,
{ {
g_async_queue_lock (retval->queue); g_async_queue_lock (retval->queue);
while (retval->num_threads < retval->max_threads) while (retval->num_threads < (guint) retval->max_threads)
{ {
GError *local_error = NULL; GError *local_error = NULL;
@ -777,12 +777,12 @@ g_thread_pool_free (GThreadPool *pool,
if (wait_) if (wait_)
{ {
while (g_async_queue_length_unlocked (real->queue) != -real->num_threads && while (g_async_queue_length_unlocked (real->queue) != (gint) -real->num_threads &&
!(immediate && real->num_threads == 0)) !(immediate && real->num_threads == 0))
g_cond_wait (&real->cond, _g_async_queue_get_mutex (real->queue)); g_cond_wait (&real->cond, _g_async_queue_get_mutex (real->queue));
} }
if (immediate || g_async_queue_length_unlocked (real->queue) == -real->num_threads) if (immediate || g_async_queue_length_unlocked (real->queue) == (gint) -real->num_threads)
{ {
/* No thread is currently doing something (and nothing is left /* No thread is currently doing something (and nothing is left
* to process in the queue) * to process in the queue)

View File

@ -237,7 +237,7 @@ again:
if (tz->t_info != NULL) if (tz->t_info != NULL)
{ {
gint idx; guint idx;
for (idx = 0; idx < tz->t_info->len; idx++) for (idx = 0; idx < tz->t_info->len; idx++)
{ {
TransitionInfo *info = &g_array_index (tz->t_info, TransitionInfo, idx); TransitionInfo *info = &g_array_index (tz->t_info, TransitionInfo, idx);
@ -575,7 +575,7 @@ init_zone_from_iana_info (GTimeZone *gtz,
trans.time = gint32_from_be (((gint32_be*)tz_transitions)[index]); trans.time = gint32_from_be (((gint32_be*)tz_transitions)[index]);
trans.info_index = tz_type_index[index]; trans.info_index = tz_type_index[index];
g_assert (trans.info_index >= 0); g_assert (trans.info_index >= 0);
g_assert (trans.info_index < gtz->t_info->len); g_assert ((guint) trans.info_index < gtz->t_info->len);
g_array_append_val (gtz->transitions, trans); g_array_append_val (gtz->transitions, trans);
} }
} }
@ -690,7 +690,7 @@ register_tzi_to_tzi (RegTZI *reg, TIME_ZONE_INFORMATION *tzi)
tzi->DaylightBias = reg->DaylightBias; tzi->DaylightBias = reg->DaylightBias;
} }
static gint static guint
rules_from_windows_time_zone (const gchar *identifier, rules_from_windows_time_zone (const gchar *identifier,
gchar **out_identifier, gchar **out_identifier,
TimeZoneRule **rules) TimeZoneRule **rules)
@ -702,7 +702,7 @@ rules_from_windows_time_zone (const gchar *identifier,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\"; "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\";
TIME_ZONE_INFORMATION tzi; TIME_ZONE_INFORMATION tzi;
DWORD size; DWORD size;
gint rules_num = 0; guint rules_num = 0;
RegTZI regtzi, regtzi_prev; RegTZI regtzi, regtzi_prev;
g_assert (out_identifier != NULL); g_assert (out_identifier != NULL);
@ -830,7 +830,7 @@ failed:
static void static void
find_relative_date (TimeZoneDate *buffer) find_relative_date (TimeZoneDate *buffer)
{ {
gint wday; guint wday;
GDate date; GDate date;
g_date_clear (&date, 1); g_date_clear (&date, 1);
wday = buffer->wday; wday = buffer->wday;
@ -923,7 +923,7 @@ fill_transition_info_from_rule (TransitionInfo *info,
static void static void
init_zone_from_rules (GTimeZone *gtz, init_zone_from_rules (GTimeZone *gtz,
TimeZoneRule *rules, TimeZoneRule *rules,
gint rules_num, guint rules_num,
gchar *identifier /* (transfer full) */) gchar *identifier /* (transfer full) */)
{ {
guint type_count = 0, trans_count = 0, info_index = 0; guint type_count = 0, trans_count = 0, info_index = 0;
@ -1214,7 +1214,7 @@ parse_tz_boundary (const gchar *identifier,
} }
} }
static gint static guint
create_ruleset_from_rule (TimeZoneRule **rules, TimeZoneRule *rule) create_ruleset_from_rule (TimeZoneRule **rules, TimeZoneRule *rule)
{ {
*rules = g_new0 (TimeZoneRule, 2); *rules = g_new0 (TimeZoneRule, 2);
@ -1306,7 +1306,7 @@ parse_identifier_boundaries (gchar **pos, TimeZoneRule *tzr)
* Creates an array of TimeZoneRule from a TZ environment variable * Creates an array of TimeZoneRule from a TZ environment variable
* type of identifier. Should free rules afterwards * type of identifier. Should free rules afterwards
*/ */
static gint static guint
rules_from_identifier (const gchar *identifier, rules_from_identifier (const gchar *identifier,
gchar **out_identifier, gchar **out_identifier,
TimeZoneRule **rules) TimeZoneRule **rules)
@ -1779,8 +1779,8 @@ g_time_zone_adjust_time (GTimeZone *tz,
GTimeType type, GTimeType type,
gint64 *time_) gint64 *time_)
{ {
gint i; guint i, intervals;
guint intervals; gboolean interval_is_dst;
if (tz->transitions == NULL) if (tz->transitions == NULL)
return 0; return 0;
@ -1822,16 +1822,21 @@ g_time_zone_adjust_time (GTimeZone *tz,
*time_ = interval_local_start (tz, i); *time_ = interval_local_start (tz, i);
} }
else if (interval_isdst (tz, i) != type) else
/* it's in this interval, but dst flag doesn't match.
* check neighbours for a better fit. */
{ {
if (i && *time_ <= interval_local_end (tz, i - 1)) interval_is_dst = interval_isdst (tz, i);
i--; if ((interval_is_dst && type != G_TIME_TYPE_DAYLIGHT) ||
(!interval_is_dst && type == G_TIME_TYPE_DAYLIGHT))
{
/* it's in this interval, but dst flag doesn't match.
* check neighbours for a better fit. */
if (i && *time_ <= interval_local_end (tz, i - 1))
i--;
else if (i < intervals && else if (i < intervals &&
*time_ >= interval_local_start (tz, i + 1)) *time_ >= interval_local_start (tz, i + 1))
i++; i++;
}
} }
} }
@ -1872,8 +1877,8 @@ g_time_zone_find_interval (GTimeZone *tz,
GTimeType type, GTimeType type,
gint64 time_) gint64 time_)
{ {
gint i; guint i, intervals;
guint intervals; gboolean interval_is_dst;
if (tz->transitions == NULL) if (tz->transitions == NULL)
return 0; return 0;
@ -1897,13 +1902,18 @@ g_time_zone_find_interval (GTimeZone *tz,
return -1; return -1;
} }
else if (interval_isdst (tz, i) != type) else
{ {
if (i && time_ <= interval_local_end (tz, i - 1)) interval_is_dst = interval_isdst (tz, i);
i--; if ((interval_is_dst && type != G_TIME_TYPE_DAYLIGHT) ||
(!interval_is_dst && type == G_TIME_TYPE_DAYLIGHT))
{
if (i && time_ <= interval_local_end (tz, i - 1))
i--;
else if (i < intervals && time_ >= interval_local_start (tz, i + 1)) else if (i < intervals && time_ >= interval_local_start (tz, i + 1))
i++; i++;
}
} }
return i; return i;

View File

@ -336,7 +336,7 @@ g_variant_ensure_size (GVariant *value)
{ {
g_assert (value->state & STATE_LOCKED); g_assert (value->state & STATE_LOCKED);
if (value->size == (gssize) -1) if (value->size == (gsize) -1)
{ {
gpointer *children; gpointer *children;
gsize n_children; gsize n_children;

View File

@ -1938,7 +1938,8 @@ number_get_value (AST *ast,
return number_overflow (ast, type, error); return number_overflow (ast, type, error);
if (negative && abs_val > G_MAXINT16) if (negative && abs_val > G_MAXINT16)
return g_variant_new_int16 (G_MININT16); return g_variant_new_int16 (G_MININT16);
return g_variant_new_int16 (negative ? -((gint16) abs_val) : abs_val); return g_variant_new_int16 (negative ?
-((gint16) abs_val) : ((gint16) abs_val));
case 'q': case 'q':
if (negative || abs_val > G_MAXUINT16) if (negative || abs_val > G_MAXUINT16)
@ -1950,7 +1951,8 @@ number_get_value (AST *ast,
return number_overflow (ast, type, error); return number_overflow (ast, type, error);
if (negative && abs_val > G_MAXINT32) if (negative && abs_val > G_MAXINT32)
return g_variant_new_int32 (G_MININT32); return g_variant_new_int32 (G_MININT32);
return g_variant_new_int32 (negative ? -((gint32) abs_val) : abs_val); return g_variant_new_int32 (negative ?
-((gint32) abs_val) : ((gint32) abs_val));
case 'u': case 'u':
if (negative || abs_val > G_MAXUINT32) if (negative || abs_val > G_MAXUINT32)
@ -1962,7 +1964,8 @@ number_get_value (AST *ast,
return number_overflow (ast, type, error); return number_overflow (ast, type, error);
if (negative && abs_val > G_MAXINT64) if (negative && abs_val > G_MAXINT64)
return g_variant_new_int64 (G_MININT64); return g_variant_new_int64 (G_MININT64);
return g_variant_new_int64 (negative ? -((gint64) abs_val) : abs_val); return g_variant_new_int64 (negative ?
-((gint64) abs_val) : ((gint64) abs_val));
case 't': case 't':
if (negative) if (negative)
@ -1974,7 +1977,8 @@ number_get_value (AST *ast,
return number_overflow (ast, type, error); return number_overflow (ast, type, error);
if (negative && abs_val > G_MAXINT32) if (negative && abs_val > G_MAXINT32)
return g_variant_new_handle (G_MININT32); return g_variant_new_handle (G_MININT32);
return g_variant_new_handle (negative ? -((gint32) abs_val) : abs_val); return g_variant_new_handle (negative ?
-((gint32) abs_val) : ((gint32) abs_val));
default: default:
return ast_type_error (ast, type, error); return ast_type_error (ast, type, error);
@ -2630,7 +2634,7 @@ g_variant_builder_add_parsed (GVariantBuilder *builder,
static gboolean static gboolean
parse_num (const gchar *num, parse_num (const gchar *num,
const gchar *limit, const gchar *limit,
gint *result) guint *result)
{ {
gchar *endptr; gchar *endptr;
gint64 bignum; gint64 bignum;
@ -2643,7 +2647,7 @@ parse_num (const gchar *num,
if (bignum < 0 || bignum > G_MAXINT) if (bignum < 0 || bignum > G_MAXINT)
return FALSE; return FALSE;
*result = bignum; *result = (guint) bignum;
return TRUE; return TRUE;
} }
@ -2799,7 +2803,7 @@ g_variant_parse_error_print_context (GError *error,
if (dash == NULL || colon < dash) if (dash == NULL || colon < dash)
{ {
gint point; guint point;
/* we have a single point */ /* we have a single point */
if (!parse_num (error->message, colon, &point)) if (!parse_num (error->message, colon, &point))
@ -2817,7 +2821,7 @@ g_variant_parse_error_print_context (GError *error,
/* We have one or two ranges... */ /* We have one or two ranges... */
if (comma && comma < colon) if (comma && comma < colon)
{ {
gint start1, end1, start2, end2; guint start1, end1, start2, end2;
const gchar *dash2; const gchar *dash2;
/* Two ranges */ /* Two ranges */
@ -2833,7 +2837,7 @@ g_variant_parse_error_print_context (GError *error,
} }
else else
{ {
gint start, end; guint start, end;
/* One range */ /* One range */
if (!parse_num (error->message, dash, &start) || !parse_num (dash + 1, colon, &end)) if (!parse_num (error->message, dash, &start) || !parse_num (dash + 1, colon, &end))

View File

@ -1552,19 +1552,20 @@ g_variant_new_strv (const gchar * const *strv,
gssize length) gssize length)
{ {
GVariant **strings; GVariant **strings;
gsize i; gsize i, length_unsigned;
g_return_val_if_fail (length == 0 || strv != NULL, NULL); g_return_val_if_fail (length == 0 || strv != NULL, NULL);
if (length < 0) if (length < 0)
length = g_strv_length ((gchar **) strv); length = g_strv_length ((gchar **) strv);
length_unsigned = length;
strings = g_new (GVariant *, length); strings = g_new (GVariant *, length_unsigned);
for (i = 0; i < length; i++) for (i = 0; i < length_unsigned; i++)
strings[i] = g_variant_ref_sink (g_variant_new_string (strv[i])); strings[i] = g_variant_ref_sink (g_variant_new_string (strv[i]));
return g_variant_new_from_children (G_VARIANT_TYPE_STRING_ARRAY, return g_variant_new_from_children (G_VARIANT_TYPE_STRING_ARRAY,
strings, length, TRUE); strings, length_unsigned, TRUE);
} }
/** /**
@ -1688,19 +1689,20 @@ g_variant_new_objv (const gchar * const *strv,
gssize length) gssize length)
{ {
GVariant **strings; GVariant **strings;
gsize i; gsize i, length_unsigned;
g_return_val_if_fail (length == 0 || strv != NULL, NULL); g_return_val_if_fail (length == 0 || strv != NULL, NULL);
if (length < 0) if (length < 0)
length = g_strv_length ((gchar **) strv); length = g_strv_length ((gchar **) strv);
length_unsigned = length;
strings = g_new (GVariant *, length); strings = g_new (GVariant *, length_unsigned);
for (i = 0; i < length; i++) for (i = 0; i < length_unsigned; i++)
strings[i] = g_variant_ref_sink (g_variant_new_object_path (strv[i])); strings[i] = g_variant_ref_sink (g_variant_new_object_path (strv[i]));
return g_variant_new_from_children (G_VARIANT_TYPE_OBJECT_PATH_ARRAY, return g_variant_new_from_children (G_VARIANT_TYPE_OBJECT_PATH_ARRAY,
strings, length, TRUE); strings, length_unsigned, TRUE);
} }
/** /**
@ -1928,19 +1930,20 @@ g_variant_new_bytestring_array (const gchar * const *strv,
gssize length) gssize length)
{ {
GVariant **strings; GVariant **strings;
gsize i; gsize i, length_unsigned;
g_return_val_if_fail (length == 0 || strv != NULL, NULL); g_return_val_if_fail (length == 0 || strv != NULL, NULL);
if (length < 0) if (length < 0)
length = g_strv_length ((gchar **) strv); length = g_strv_length ((gchar **) strv);
length_unsigned = length;
strings = g_new (GVariant *, length); strings = g_new (GVariant *, length_unsigned);
for (i = 0; i < length; i++) for (i = 0; i < length_unsigned; i++)
strings[i] = g_variant_ref_sink (g_variant_new_bytestring (strv[i])); strings[i] = g_variant_ref_sink (g_variant_new_bytestring (strv[i]));
return g_variant_new_from_children (G_VARIANT_TYPE_BYTESTRING_ARRAY, return g_variant_new_from_children (G_VARIANT_TYPE_BYTESTRING_ARRAY,
strings, length, TRUE); strings, length_unsigned, TRUE);
} }
/** /**

View File

@ -108,10 +108,10 @@ typedef struct
/* Hard-code the base types in a constant array */ /* Hard-code the base types in a constant array */
static const GVariantTypeInfo g_variant_type_info_basic_table[24] = { static const GVariantTypeInfo g_variant_type_info_basic_table[24] = {
#define fixed_aligned(x) x, x - 1 #define fixed_aligned(x) x, x - 1, 0
#define not_a_type 0, #define not_a_type 0, 0, 0
#define unaligned 0, 0 #define unaligned 0, 0, 0
#define aligned(x) 0, x - 1 #define aligned(x) 0, x - 1, 0
/* 'b' */ { fixed_aligned(1) }, /* boolean */ /* 'b' */ { fixed_aligned(1) }, /* boolean */
/* 'c' */ { not_a_type }, /* 'c' */ { not_a_type },
/* 'd' */ { fixed_aligned(8) }, /* double */ /* 'd' */ { fixed_aligned(8) }, /* double */
@ -362,7 +362,7 @@ static void
tuple_info_free (GVariantTypeInfo *info) tuple_info_free (GVariantTypeInfo *info)
{ {
TupleInfo *tuple_info; TupleInfo *tuple_info;
gint i; gsize i;
g_assert (info->container_class == GV_TUPLE_INFO_CLASS); g_assert (info->container_class == GV_TUPLE_INFO_CLASS);
tuple_info = (TupleInfo *) info; tuple_info = (TupleInfo *) info;
@ -640,7 +640,7 @@ tuple_set_base_info (TupleInfo *info)
* offsets are stored and the last item is fixed-sized too (since * offsets are stored and the last item is fixed-sized too (since
* an offset is never stored for the last item). * an offset is never stored for the last item).
*/ */
if (m->i == -1 && m->type_info->fixed_size) if (m->i == (gsize) -1 && m->type_info->fixed_size)
/* in that case, the fixed size can be found by finding the /* in that case, the fixed size can be found by finding the
* start of the last item (in the usual way) and adding its * start of the last item (in the usual way) and adding its
* fixed size. * fixed size.

View File

@ -183,7 +183,7 @@ static guint
honeyman_hash (gconstpointer key) honeyman_hash (gconstpointer key)
{ {
const gchar *name = (const gchar *) key; const gchar *name = (const gchar *) key;
gint size; gsize size;
guint sum = 0; guint sum = 0;
g_assert (name != NULL); g_assert (name != NULL);
@ -1347,7 +1347,7 @@ test_lookup_extended (void)
struct _GHashTable struct _GHashTable
{ {
gint size; gsize size;
gint mod; gint mod;
guint mask; guint mask;
gint nnodes; gint nnodes;
@ -1374,7 +1374,7 @@ struct _GHashTable
static void static void
count_keys (GHashTable *h, gint *unused, gint *occupied, gint *tombstones) count_keys (GHashTable *h, gint *unused, gint *occupied, gint *tombstones)
{ {
gint i; gsize i;
*unused = 0; *unused = 0;
*occupied = 0; *occupied = 0;
@ -1410,7 +1410,7 @@ fetch_key_or_value (gpointer a, guint index, gboolean is_big)
static void static void
check_data (GHashTable *h) check_data (GHashTable *h)
{ {
gint i; gsize i;
for (i = 0; i < h->size; i++) for (i = 0; i < h->size; i++)
{ {

View File

@ -352,6 +352,8 @@ if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
'-Wmisleading-indentation', '-Wmisleading-indentation',
'-Wstrict-prototypes', '-Wstrict-prototypes',
'-Wunused', '-Wunused',
# Due to maintained deprecated code, we do not want to see unused parameters
'-Wno-unused-parameter',
# Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support # Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
# building with -Wbad-function-cast. # building with -Wbad-function-cast.
'-Wno-bad-function-cast', '-Wno-bad-function-cast',