gobject: Fix various straightforward -Wsign-conversion warnings

None of these should have caused user-visible bugs.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
This commit is contained in:
Philip Withnall
2025-04-11 15:01:27 +01:00
parent b9d2719222
commit efed9028fa
5 changed files with 38 additions and 32 deletions

View File

@@ -95,11 +95,11 @@
#define CLOSURE_MAX_N_GUARDS ((1 << 1) - 1)
#define CLOSURE_MAX_N_FNOTIFIERS ((1 << 2) - 1)
#define CLOSURE_MAX_N_INOTIFIERS ((1 << 8) - 1)
#define CLOSURE_N_MFUNCS(cl) (((cl)->n_guards << 1L))
#define CLOSURE_N_MFUNCS(cl) ((size_t) ((cl)->n_guards << 1L))
/* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */
#define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \
#define CLOSURE_N_NOTIFIERS(cl) ((size_t) (CLOSURE_N_MFUNCS (cl) + \
(cl)->n_fnotifiers + \
(cl)->n_inotifiers)
(cl)->n_inotifiers))
/* A copy of the flags bitfield from the beginning of `struct _GClosure`, which
* is in union with an int for atomic access to all fields at the same time.
@@ -223,7 +223,7 @@ g_closure_new_simple (guint sizeof_closure,
gpointer data)
{
GClosure *closure;
gint private_size;
size_t private_size;
gchar *allocated;
g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL);
@@ -1316,7 +1316,7 @@ value_to_ffi_type (const GValue *gvalue,
case G_TYPE_FLAGS:
g_assert (enum_tmpval != NULL);
rettype = &ffi_type_uint;
*enum_tmpval = g_value_get_flags (gvalue);
*enum_tmpval = (int) g_value_get_flags (gvalue);
*value = enum_tmpval;
*tmpval_used = TRUE;
break;
@@ -1560,10 +1560,10 @@ g_cclosure_marshal_generic (GClosure *closure,
{
ffi_type *rtype;
void *rvalue;
int n_args;
size_t n_args;
ffi_type **atypes;
void **args;
int i;
size_t i;
ffi_cif cif;
GCClosure *cc = (GCClosure*) closure;
gint *enum_tmpval;
@@ -1659,17 +1659,22 @@ g_cclosure_marshal_generic_va (GClosure *closure,
{
ffi_type *rtype;
void *rvalue;
int n_args;
size_t n_args;
size_t unsigned_n_params;
ffi_type **atypes;
void **args;
va_arg_storage *storage;
int i;
size_t i;
ffi_cif cif;
GCClosure *cc = (GCClosure*) closure;
gint *enum_tmpval;
gboolean tmpval_used = FALSE;
va_list args_copy;
g_return_if_fail (n_params >= 0);
unsigned_n_params = (size_t) n_params;
enum_tmpval = g_alloca (sizeof (gint));
if (return_value && G_VALUE_TYPE (return_value))
{
@@ -1682,10 +1687,10 @@ g_cclosure_marshal_generic_va (GClosure *closure,
rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg)));
n_args = n_params + 2;
n_args = unsigned_n_params + 2;
atypes = g_alloca (sizeof (ffi_type *) * n_args);
args = g_alloca (sizeof (gpointer) * n_args);
storage = g_alloca (sizeof (va_arg_storage) * n_params);
storage = g_alloca (sizeof (va_arg_storage) * unsigned_n_params);
if (G_CCLOSURE_SWAP_DATA (closure))
{
@@ -1705,7 +1710,7 @@ g_cclosure_marshal_generic_va (GClosure *closure,
va_copy (args_copy, args_list);
/* Box non-primitive arguments */
for (i = 0; i < n_params; i++)
for (i = 0; i < unsigned_n_params; i++)
{
GType type = param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
GType fundamental = G_TYPE_FUNDAMENTAL (type);
@@ -1738,7 +1743,7 @@ g_cclosure_marshal_generic_va (GClosure *closure,
ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args);
/* Unbox non-primitive arguments */
for (i = 0; i < n_params; i++)
for (i = 0; i < unsigned_n_params; i++)
{
GType type = param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE;
GType fundamental = G_TYPE_FUNDAMENTAL (type);

View File

@@ -956,7 +956,7 @@ param_spec_pool_hash (gconstpointer key_spec)
guint h = (guint) key->owner_type;
for (p = key->name; *p; p++)
h = (h << 5) - h + *p;
h = (guint) (h << 5) - h + (guint) *p;
return h;
}
@@ -1182,11 +1182,11 @@ g_param_spec_pool_lookup (GParamSpecPool *pool,
/* strip type prefix */
if (delim && delim[1] == ':')
{
guint l = delim - param_name;
size_t l = (size_t) (delim - param_name);
gchar stack_buffer[32], *buffer = l < 32 ? stack_buffer : g_new (gchar, l + 1);
GType type;
strncpy (buffer, param_name, delim - param_name);
strncpy (buffer, param_name, l);
buffer[l] = 0;
type = g_type_from_name (buffer);
if (l >= 32)
@@ -1311,7 +1311,7 @@ pool_depth_list (gpointer key,
GSList **slists = data[0];
GType owner_type = (GType) data[1];
GHashTable *ht = data[2];
int *count = data[3];
unsigned int *count = data[3];
if (g_type_is_a (owner_type, pspec->owner_type) &&
should_list_pspec (pspec, owner_type, ht))
@@ -1350,7 +1350,7 @@ pool_depth_list_for_interface (gpointer key,
GSList **slists = data[0];
GType owner_type = (GType) data[1];
GHashTable *ht = data[2];
int *count = data[3];
unsigned int *count = data[3];
if (pspec->owner_type == owner_type &&
should_list_pspec (pspec, owner_type, ht))
@@ -1382,7 +1382,7 @@ g_param_spec_pool_list (GParamSpecPool *pool,
GSList **slists, *node;
gpointer data[4];
guint d, i;
int n_pspecs = 0;
unsigned int n_pspecs = 0;
g_return_val_if_fail (pool != NULL, NULL);
g_return_val_if_fail (owner_type > 0, NULL);

View File

@@ -121,7 +121,8 @@ g_child_watch_closure_callback (GPid pid,
#ifdef G_OS_UNIX
g_value_init (&params[0], G_TYPE_ULONG);
g_value_set_ulong (&params[0], pid);
G_STATIC_ASSERT (sizeof (pid) <= sizeof (unsigned long));
g_value_set_ulong (&params[0], (gulong) pid);
#endif
#ifdef G_OS_WIN32
g_value_init (&params[0], G_TYPE_POINTER);

View File

@@ -125,9 +125,9 @@
* larger alignment than this, but we don't need to
* do better than malloc.
*/
#define STRUCT_ALIGNMENT (2 * sizeof (gsize))
#define STRUCT_ALIGNMENT (2u * sizeof (gsize))
#define ALIGN_STRUCT(offset) \
((offset + (STRUCT_ALIGNMENT - 1)) & -STRUCT_ALIGNMENT)
(((size_t) (offset) + (STRUCT_ALIGNMENT - 1u)) & -STRUCT_ALIGNMENT)
/* --- typedefs --- */
@@ -442,7 +442,7 @@ type_node_any_new_W (TypeNode *pnode,
else
{
node->supers[0] = type;
memcpy (node->supers + 1, pnode->supers, sizeof (GType) * (1 + pnode->n_supers + 1));
memcpy (node->supers + 1, pnode->supers, sizeof (GType) * (1u + pnode->n_supers + 1u));
node->is_abstract = (type_flags & G_TYPE_FLAG_ABSTRACT) != 0;
node->is_classed = pnode->is_classed;
@@ -1239,7 +1239,7 @@ type_data_ref_Wm (TypeNode *node)
static gboolean
iface_node_has_available_offset_L (TypeNode *iface_node,
gsize offset,
int for_index)
size_t for_index)
{
guint8 *offsets;
@@ -1263,8 +1263,7 @@ find_free_iface_offset_L (IFaceEntries *entries)
IFaceEntry *entry;
TypeNode *iface_node;
gsize offset;
int i;
int n_entries;
size_t i, n_entries;
n_entries = IFACE_ENTRIES_N_ENTRIES (entries);
offset = 0;
@@ -1290,7 +1289,7 @@ find_free_iface_offset_L (IFaceEntries *entries)
static void
iface_node_set_offset_L (TypeNode *iface_node,
gsize offset,
int index)
size_t index)
{
guint8 *offsets, *old_offsets;
gsize new_size, old_size;
@@ -1821,8 +1820,8 @@ g_type_create_instance (GType type)
GTypeInstance *instance;
GTypeClass *class;
gchar *allocated;
gint private_size;
gint ivar_size;
size_t private_size;
size_t ivar_size;
guint i;
node = lookup_type_node_I (type);
@@ -1928,8 +1927,8 @@ g_type_free_instance (GTypeInstance *instance)
TypeNode *node;
GTypeClass *class;
gchar *allocated;
gint private_size;
gint ivar_size;
size_t private_size;
size_t ivar_size;
g_return_if_fail (instance != NULL && instance->g_class != NULL);

View File

@@ -62,7 +62,7 @@
* as described above.
*/
#define GROUP_N_VALUES (8) /* power of 2 !! */
#define GROUP_N_VALUES (8u) /* power of 2 !! */
/* --- functions --- */
@@ -99,6 +99,7 @@ value_array_grow (GValueArray *value_array,
{
guint i = value_array->n_prealloced;
/* round up to the next multiple of GROUP_N_VALUES */
value_array->n_prealloced = (value_array->n_values + GROUP_N_VALUES - 1) & ~(GROUP_N_VALUES - 1);
value_array->values = g_renew (GValue, value_array->values, value_array->n_prealloced);
if (!zero_init)