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-Url: http://drtracing.org/?a=commitdiff_plain;h=cae67efbd9ddf2cee6bbefec076dc8933ababc43;p=deliverable%2Fbabeltrace.git 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 9e264a415..14d925215 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);