girnode: Use size_t to compute gir node size and ensure value is valid

This commit is contained in:
Marco Trevisan (Treviño) 2024-01-16 02:22:24 +01:00
parent a73cc6d5a2
commit c8eeca9492

View File

@ -435,7 +435,7 @@ uint32_t
gi_ir_node_get_size (GIIrNode *node) gi_ir_node_get_size (GIIrNode *node)
{ {
GList *l; GList *l;
int size, n; size_t size, n;
switch (node->type) switch (node->type)
{ {
@ -564,9 +564,11 @@ gi_ir_node_get_size (GIIrNode *node)
size = 0; size = 0;
} }
g_debug ("node %p type '%s' size %d", node, g_debug ("node %p type '%s' size %zu", node,
gi_ir_node_type_to_string (node->type), size); gi_ir_node_type_to_string (node->type), size);
g_assert (size <= G_MAXUINT32);
return size; return size;
} }
@ -575,7 +577,7 @@ add_attribute_size (gpointer key, gpointer value, gpointer data)
{ {
const char *key_str = key; const char *key_str = key;
const char *value_str = value; const char *value_str = value;
int *size_p = data; size_t *size_p = data;
*size_p += sizeof (AttributeBlob); *size_p += sizeof (AttributeBlob);
*size_p += ALIGN_VALUE (strlen (key_str) + 1, 4); *size_p += ALIGN_VALUE (strlen (key_str) + 1, 4);
@ -588,7 +590,7 @@ gi_ir_node_get_full_size_internal (GIIrNode *parent,
GIIrNode *node) GIIrNode *node)
{ {
GList *l; GList *l;
int size, n; size_t size, n;
if (node == NULL && parent != NULL) if (node == NULL && parent != NULL)
g_error ("Caught NULL node, parent=%s", parent->name); g_error ("Caught NULL node, parent=%s", parent->name);
@ -882,7 +884,7 @@ gi_ir_node_get_full_size_internal (GIIrNode *parent,
size = 0; size = 0;
} }
g_debug ("node %s%s%s%p type '%s' full size %d", g_debug ("node %s%s%s%p type '%s' full size %zu",
node->name ? "'" : "", node->name ? "'" : "",
node->name ? node->name : "", node->name ? node->name : "",
node->name ? "' " : "", node->name ? "' " : "",
@ -890,6 +892,8 @@ gi_ir_node_get_full_size_internal (GIIrNode *parent,
g_hash_table_foreach (node->attributes, add_attribute_size, &size); g_hash_table_foreach (node->attributes, add_attribute_size, &size);
g_assert (size <= G_MAXUINT32);
return size; return size;
} }