girnode: Improve int types in GIIrNodeVFunc

`GIIrNodeVFunc` is built dynamically at runtime (rather than being
mmapped from disk), so its types can accurately reflect their runtime
semantics, rather than an on-disk format.

As part of this, switch from `atoi()` to `g_ascii_string_to_unsigned()`
for parsing the relevant fields from a GIR XML file. This means we now
get error handling for invalid integers.

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

Helps: #3155
This commit is contained in:
Philip Withnall 2024-01-26 09:19:11 +00:00
parent 468b926c2b
commit 48d9f356c3
2 changed files with 10 additions and 4 deletions

View File

@ -243,7 +243,7 @@ struct _GIIrNodeVFunc
GList *parameters; /* (element-type GIIrNode) (owned) */
GIIrNodeParam *result; /* (owned) */
int offset;
size_t offset;
};
struct _GIIrNodeField

View File

@ -2561,6 +2561,7 @@ start_vfunc (GMarkupParseContext *context,
const char *throws;
GIIrNodeInterface *iface;
GIIrNodeVFunc *vfunc;
guint64 parsed_offset;
if (!(strcmp (element_name, "virtual-method") == 0 &&
(ctx->state == STATE_CLASS ||
@ -2620,10 +2621,15 @@ start_vfunc (GMarkupParseContext *context,
else
vfunc->throws = FALSE;
if (offset)
vfunc->offset = atoi (offset);
else
if (offset == NULL)
vfunc->offset = 0xFFFF;
else if (g_ascii_string_to_unsigned (offset, 10, 0, G_MAXSIZE, &parsed_offset, error))
vfunc->offset = parsed_offset;
else
{
gi_ir_node_free ((GIIrNode *) vfunc);
return FALSE;
}
vfunc->invoker = g_strdup (invoker);