mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-23 22:16:16 +01:00
girnode: Improve int types in GIIrNodeUnion
`GIIrNodeUnion` 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 Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
2e7518bcc1
commit
0909b2e3ac
@ -384,7 +384,7 @@ struct _GIIrNodeUnion
|
||||
size_t size;
|
||||
GIIrOffsetsState offsets_state;
|
||||
|
||||
int discriminator_offset;
|
||||
size_t discriminator_offset;
|
||||
GIIrNodeType *discriminator_type; /* (owned) */
|
||||
};
|
||||
|
||||
|
@ -2810,6 +2810,8 @@ start_discriminator (GMarkupParseContext *context,
|
||||
{
|
||||
const char *type;
|
||||
const char *offset;
|
||||
guint64 parsed_offset;
|
||||
|
||||
if (!(strcmp (element_name, "discriminator") == 0 &&
|
||||
ctx->state == STATE_UNION))
|
||||
return FALSE;
|
||||
@ -2829,8 +2831,11 @@ start_discriminator (GMarkupParseContext *context,
|
||||
|
||||
((GIIrNodeUnion *)CURRENT_NODE (ctx))->discriminator_type
|
||||
= parse_type (ctx, type);
|
||||
((GIIrNodeUnion *)CURRENT_NODE (ctx))->discriminator_offset
|
||||
= atoi (offset);
|
||||
|
||||
if (g_ascii_string_to_unsigned (offset, 10, 0, G_MAXSIZE, &parsed_offset, error))
|
||||
((GIIrNodeUnion *)CURRENT_NODE (ctx))->discriminator_offset = parsed_offset;
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user