Merge branch 'sign-compare' into 'master'

Fix some -Wsign-compare warnings

See merge request GNOME/glib!162
This commit is contained in:
Philip Withnall 2018-07-11 10:07:34 +00:00
commit c182cd68c9
4 changed files with 27 additions and 20 deletions

View File

@ -139,9 +139,9 @@ struct _GRealArray
g_array_elt_zero ((array), (array)->len, 1); \ g_array_elt_zero ((array), (array)->len, 1); \
}G_STMT_END }G_STMT_END
static guint g_nearest_pow (gint num) G_GNUC_CONST; static guint g_nearest_pow (guint num) G_GNUC_CONST;
static void g_array_maybe_expand (GRealArray *array, static void g_array_maybe_expand (GRealArray *array,
gint len); guint len);
/** /**
* g_array_new: * g_array_new:
@ -789,7 +789,7 @@ g_array_sort_with_data (GArray *farray,
* such power does not fit in a guint * such power does not fit in a guint
*/ */
static guint static guint
g_nearest_pow (gint num) g_nearest_pow (guint num)
{ {
guint n = 1; guint n = 1;
@ -801,7 +801,7 @@ g_nearest_pow (gint num)
static void static void
g_array_maybe_expand (GRealArray *array, g_array_maybe_expand (GRealArray *array,
gint len) guint len)
{ {
guint want_alloc = g_array_elt_len (array, array->len + len + guint want_alloc = g_array_elt_len (array, array->len + len +
array->zero_terminated); array->zero_terminated);
@ -1189,27 +1189,31 @@ g_ptr_array_set_size (GPtrArray *array,
gint length) gint length)
{ {
GRealPtrArray *rarray = (GRealPtrArray *)array; GRealPtrArray *rarray = (GRealPtrArray *)array;
guint length_unsigned;
g_return_if_fail (rarray); g_return_if_fail (rarray);
g_return_if_fail (rarray->len == 0 || (rarray->len != 0 && rarray->pdata != NULL)); g_return_if_fail (rarray->len == 0 || (rarray->len != 0 && rarray->pdata != NULL));
g_return_if_fail (length >= 0);
if (length > rarray->len) length_unsigned = (guint) length;
if (length_unsigned > rarray->len)
{ {
int i; guint i;
g_ptr_array_maybe_expand (rarray, (length - rarray->len)); g_ptr_array_maybe_expand (rarray, (length_unsigned - rarray->len));
/* This is not /* This is not
* memset (array->pdata + array->len, 0, * memset (array->pdata + array->len, 0,
* sizeof (gpointer) * (length - array->len)); * sizeof (gpointer) * (length_unsigned - array->len));
* to make it really portable. Remember (void*)NULL needn't be * to make it really portable. Remember (void*)NULL needn't be
* bitwise zero. It of course is silly not to use memset (..,0,..). * bitwise zero. It of course is silly not to use memset (..,0,..).
*/ */
for (i = rarray->len; i < length; i++) for (i = rarray->len; i < length_unsigned; i++)
rarray->pdata[i] = NULL; rarray->pdata[i] = NULL;
} }
else if (length < rarray->len) else if (length_unsigned < rarray->len)
g_ptr_array_remove_range (array, length, rarray->len - length); g_ptr_array_remove_range (array, length_unsigned, rarray->len - length_unsigned);
rarray->len = length; rarray->len = length_unsigned;
} }
static gpointer static gpointer

View File

@ -372,7 +372,7 @@ g_queue_push_nth (GQueue *queue,
{ {
g_return_if_fail (queue != NULL); g_return_if_fail (queue != NULL);
if (n < 0 || n >= queue->length) if (n < 0 || (guint) n >= queue->length)
{ {
g_queue_push_tail (queue, data); g_queue_push_tail (queue, data);
return; return;
@ -475,7 +475,7 @@ g_queue_push_nth_link (GQueue *queue,
g_return_if_fail (queue != NULL); g_return_if_fail (queue != NULL);
g_return_if_fail (link_ != NULL); g_return_if_fail (link_ != NULL);
if (n < 0 || n >= queue->length) if (n < 0 || (guint) n >= queue->length)
{ {
g_queue_push_tail_link (queue, link_); g_queue_push_tail_link (queue, link_);
return; return;
@ -749,7 +749,7 @@ g_queue_peek_nth_link (GQueue *queue,
guint n) guint n)
{ {
GList *link; GList *link;
gint i; guint i;
g_return_val_if_fail (queue != NULL, NULL); g_return_val_if_fail (queue != NULL, NULL);

View File

@ -388,7 +388,7 @@ g_rand_set_seed_array (GRand *rand,
const guint32 *seed, const guint32 *seed,
guint seed_length) guint seed_length)
{ {
int i, j, k; guint i, j, k;
g_return_if_fail (rand != NULL); g_return_if_fail (rand != NULL);
g_return_if_fail (seed_length >= 1); g_return_if_fail (seed_length >= 1);

View File

@ -1054,7 +1054,7 @@ g_variant_type_new_tuple_slow (const GVariantType * const *items,
* happen only in truly insane code, so it can be slow. * happen only in truly insane code, so it can be slow.
*/ */
GString *string; GString *string;
gsize i; gint i;
string = g_string_new ("("); string = g_string_new ("(");
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
@ -1080,16 +1080,19 @@ g_variant_type_new_tuple (const GVariantType * const *items,
char buffer[1024]; char buffer[1024];
gsize offset; gsize offset;
gsize i; gsize i;
gsize length_unsigned;
g_return_val_if_fail (length == 0 || items != NULL, NULL); g_return_val_if_fail (length == 0 || items != NULL, NULL);
if (length < 0) if (length < 0)
for (length = 0; items[length] != NULL; length++); for (length_unsigned = 0; items[length_unsigned] != NULL; length_unsigned++);
else
length_unsigned = (gsize) length;
offset = 0; offset = 0;
buffer[offset++] = '('; buffer[offset++] = '(';
for (i = 0; i < length; i++) for (i = 0; i < length_unsigned; i++)
{ {
const GVariantType *type; const GVariantType *type;
gsize size; gsize size;
@ -1100,7 +1103,7 @@ g_variant_type_new_tuple (const GVariantType * const *items,
size = g_variant_type_get_string_length (type); size = g_variant_type_get_string_length (type);
if (offset + size >= sizeof buffer) /* leave room for ')' */ if (offset + size >= sizeof buffer) /* leave room for ')' */
return g_variant_type_new_tuple_slow (items, length); return g_variant_type_new_tuple_slow (items, length_unsigned);
memcpy (&buffer[offset], type, size); memcpy (&buffer[offset], type, size);
offset += size; offset += size;