From 6a43d7325c8e5271a0fecc0b8bd2c557d98beaf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 13 May 2015 14:11:35 -0400 Subject: [PATCH] Fix: ir: disallow setting the alignment of certain types MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Setting the alignment of sequences, arrays, variants and structures makes no sense. Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/event-types.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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: -- 2.34.1