From 9ebed4deab20fdd71eeefaded2cc624705cfcddf Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Tue, 16 Apr 2024 05:52:19 -0400 Subject: [PATCH] align data --- src/sparsemap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sparsemap.c b/src/sparsemap.c index 1cd69ac..67e8b14 100644 --- a/src/sparsemap.c +++ b/src/sparsemap.c @@ -818,7 +818,8 @@ sparsemap(size_t size) sparsemap_t *map = (sparsemap_t *)calloc(1, total_size); if (map) { - sparsemap_init(map, (uint8_t *)((uintptr_t)map + sizeof(sparsemap_t) + padding), size); + uint8_t *data = (uint8_t *)(((uintptr_t)map + sizeof(sparsemap_t)) & ~ (uintptr_t)7); + sparsemap_init(map, data, size); __sm_when_diag({ __sm_assert(IS_8_BYTE_ALIGNED(map->m_data)); }); } sparsemap_clear(map); @@ -875,7 +876,7 @@ sparsemap_set_data_size(sparsemap_t *map, size_t size) } memset(((uint8_t *)m) + sizeof(sparsemap_t) + (m->m_capacity * sizeof(uint8_t)), 0, size - m->m_capacity + padding); m->m_capacity = data_size; - m->m_data = (uint8_t *)((uintptr_t)m + sizeof(sparsemap_t) + padding); + m->m_data = (uint8_t *)(((uintptr_t)m + sizeof(sparsemap_t)) & ~ (uintptr_t)7); __sm_when_diag({ __sm_assert(IS_8_BYTE_ALIGNED(m->m_data)); }) return m; } else { map->m_capacity = size;