Use offsetof() when sizing dynamic structures.

Base dynamic structure size on offsetof(), rather than subtracting the
size of the dynamic structure member.  Results could differ on systems
with strict data structure alignment requirements.
This commit is contained in:
Jason Evans
2010-10-01 18:02:43 -07:00
parent 3377ffa1f4
commit c2fc8c8b3a
3 changed files with 7 additions and 6 deletions
+2 -2
View File
@@ -101,8 +101,8 @@ arenas_extend(unsigned ind)
arena_t *ret;
/* Allocate enough space for trailing bins. */
ret = (arena_t *)base_alloc(sizeof(arena_t)
+ (sizeof(arena_bin_t) * (nbins - 1)));
ret = (arena_t *)base_alloc(offsetof(arena_t, bins)
+ (sizeof(arena_bin_t) * nbins));
if (ret != NULL && arena_new(ret, ind) == false) {
arenas[ind] = ret;
return (ret);