Fix: require power of two for type alignment
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 14 Jul 2015 23:36:15 +0000 (19:36 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 16 Jul 2015 22:13:38 +0000 (18:13 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-types.c

index df117474561098864e2bd38a550bb4e46a24089e..da0ecd6d89acf91c150a8dc4a3ee24133ef1aae9 100644 (file)
@@ -1780,14 +1780,20 @@ end:
        return ret;
 }
 
+static inline
+int is_power_of_two(unsigned int value)
+{
+       return ((value & (value - 1)) == 0) && value > 0;
+}
+
 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))) {
+       /* Alignment must be a power of two */
+       if (!type || type->frozen || !is_power_of_two(alignment)) {
                ret = -1;
                goto end;
        }
This page took 0.025741 seconds and 4 git commands to generate.