From 03bad7894782c1f3192cc8930027d7dda3bfa0ca Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 10 Jul 2018 14:15:42 +0200 Subject: [PATCH] garray: Fix -Wsign-compare warnings Signed-off-by: Philip Withnall --- glib/garray.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/glib/garray.c b/glib/garray.c index 8f908e443..5b71c887a 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -139,9 +139,9 @@ struct _GRealArray g_array_elt_zero ((array), (array)->len, 1); \ }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, - gint len); + guint len); /** * g_array_new: @@ -789,7 +789,7 @@ g_array_sort_with_data (GArray *farray, * such power does not fit in a guint */ static guint -g_nearest_pow (gint num) +g_nearest_pow (guint num) { guint n = 1; @@ -801,7 +801,7 @@ g_nearest_pow (gint num) static void g_array_maybe_expand (GRealArray *array, - gint len) + guint len) { guint want_alloc = g_array_elt_len (array, array->len + len + array->zero_terminated); @@ -1189,27 +1189,31 @@ g_ptr_array_set_size (GPtrArray *array, gint length) { GRealPtrArray *rarray = (GRealPtrArray *)array; + guint length_unsigned; g_return_if_fail (rarray); 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; - g_ptr_array_maybe_expand (rarray, (length - rarray->len)); + guint i; + g_ptr_array_maybe_expand (rarray, (length_unsigned - rarray->len)); /* This is not * 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 * 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; } - else if (length < rarray->len) - g_ptr_array_remove_range (array, length, rarray->len - length); + else if (length_unsigned < rarray->len) + g_ptr_array_remove_range (array, length_unsigned, rarray->len - length_unsigned); - rarray->len = length; + rarray->len = length_unsigned; } static gpointer