From: Philippe Proulx Date: Tue, 14 Jul 2015 23:36:15 +0000 (-0400) Subject: Fix: require power of two for type alignment X-Git-Tag: v2.0.0-pre1~1212 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=9ad2f879463a33f00793d2f8c0f27ca227aca468 Fix: require power of two for type alignment Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index df117474..da0ecd6d 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -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; }