align data

This commit is contained in:
Gregory Burd 2024-04-16 05:52:19 -04:00
parent 9109a7430c
commit 9ebed4deab

View file

@ -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;