Fix: ir: disallow setting the alignment of certain types
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 13 May 2015 18:11:35 +0000 (14:11 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 13 May 2015 18:13:37 +0000 (14:13 -0400)
Setting the alignment of sequences, arrays, variants and structures
makes no sense.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-types.c

index 12172e5df1002ee7228b6d50b0d00cd63c84f5cf..40c26da01d47cbed5966f1318712dc2529007d8e 100644 (file)
@@ -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:
This page took 0.026084 seconds and 4 git commands to generate.