From 48d9f356c312c70bc1be120fbf595130785c7089 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 26 Jan 2024 09:19:11 +0000 Subject: [PATCH] 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 Helps: #3155 --- girepository/girnode-private.h | 2 +- girepository/girparser.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/girepository/girnode-private.h b/girepository/girnode-private.h index 89f87864e..0d593d70f 100644 --- a/girepository/girnode-private.h +++ b/girepository/girnode-private.h @@ -243,7 +243,7 @@ struct _GIIrNodeVFunc GList *parameters; /* (element-type GIIrNode) (owned) */ GIIrNodeParam *result; /* (owned) */ - int offset; + size_t offset; }; struct _GIIrNodeField diff --git a/girepository/girparser.c b/girepository/girparser.c index 5de5177d4..f14fa1bed 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -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);