From: Jérémie Galarneau Date: Wed, 13 May 2015 18:11:35 +0000 (-0400) Subject: Fix: ir: disallow setting the alignment of certain types X-Git-Tag: v2.0.0-pre1~1231 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=6a43d7325c8e5271a0fecc0b8bd2c557d98beaf9 Fix: ir: disallow setting the alignment of certain types Setting the alignment of sequences, arrays, variants and structures makes no sense. Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 12172e5d..40c26da0 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -1778,6 +1778,7 @@ int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment) { int ret = 0; + enum ctf_type_id type_id; /* Alignment must be bit-aligned (1) or byte aligned */ if (!type || type->frozen || (alignment != 1 && (alignment & 0x7))) { @@ -1785,12 +1786,25 @@ int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, goto end; } + type_id = bt_ctf_field_type_get_type_id(type); + if (type_id == CTF_TYPE_UNKNOWN) { + ret = -1; + goto end; + } + if (type->declaration->id == CTF_TYPE_STRING && alignment != CHAR_BIT) { ret = -1; goto end; } + if (type_id == CTF_TYPE_STRUCT || type_id == CTF_TYPE_VARIANT || + type_id == CTF_TYPE_SEQUENCE || type_id == CTF_TYPE_ARRAY) { + /* Setting an alignment on these types makes no sense */ + ret = -1; + goto end; + } + type->declaration->alignment = alignment; ret = 0; end: