From: Fredrik Markström Date: Fri, 16 May 2014 02:10:38 +0000 (+0800) Subject: Fix: Align buffers from objstack_alloc on sizeof(void *) X-Git-Tag: v1.2.3~8 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=ce3b3e38edc0d980685a593b68fb52b4c351c0c4 Fix: Align buffers from objstack_alloc on sizeof(void *) The buffers from objstack_alloc will store pointers, so they must be aligned on a pointer's size, or else it will cause issues on the CPUs which do not support unaligned addresses access. Signed-off-by: Fredrik Markstrom Signed-off-by: Roy Li Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/metadata/objstack.c b/formats/ctf/metadata/objstack.c index 9e264a41..14d92521 100644 --- a/formats/ctf/metadata/objstack.c +++ b/formats/ctf/metadata/objstack.c @@ -27,6 +27,7 @@ #include #include #include +#include #define OBJSTACK_INIT_LEN 128 #define OBJSTACK_POISON 0xcc @@ -39,7 +40,7 @@ struct objstack_node { struct bt_list_head node; size_t len; size_t used_len; - char data[]; + char __attribute__ ((aligned (sizeof(void *)))) data[]; }; BT_HIDDEN @@ -118,6 +119,8 @@ void *objstack_alloc(struct objstack *objstack, size_t len) struct objstack_node *last_node; void *p; + len = ALIGN(len, sizeof(void *)); + /* Get last node */ last_node = bt_list_entry(objstack->head.prev, struct objstack_node, node);