diff options
author | Evan Huus <eapache@gmail.com> | 2012-12-08 21:08:29 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2012-12-08 21:08:29 +0000 |
commit | af700fa79ad4adb4be3e6380cb932a8f20959b29 (patch) | |
tree | 1bea852a77b228323b4ead23a486f621f9b7e987 | |
parent | 1f4d7cb6a7e551c9f858eb9cc8480b74036d1fdf (diff) |
Make sure the wmem block allocator returns aligned memory.
svn path=/trunk/; revision=46468
-rw-r--r-- | epan/wmem/wmem_allocator_block.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/epan/wmem/wmem_allocator_block.c b/epan/wmem/wmem_allocator_block.c index ec6e1835da..498ed5156a 100644 --- a/epan/wmem/wmem_allocator_block.c +++ b/epan/wmem/wmem_allocator_block.c @@ -68,6 +68,7 @@ wmem_block_free_block(wmem_block_t *block) static void * wmem_block_alloc(void *private_data, const size_t size) { + guint8 align; void *buf; wmem_block_t *block; wmem_block_allocator_t *allocator = (wmem_block_allocator_t*) private_data; @@ -108,6 +109,22 @@ wmem_block_alloc(void *private_data, const size_t size) buf = ((guint8*) block->base) + block->offset; block->offset += size; block->remaining -= size; + + /* Make sure that our next allocation is 8-byte aligned. This wastes a + * little space on 32-bit systems, but greatly simplifies the logic. */ + align = block->offset & 0x07; + if (align) { + + align = 0x08 - align; + + if (align > block->remaining) { + align = block->remaining; + } + + block->offset += align; + block->remaining -= align; + } + return buf; } |