fast-import: fix unalinged allocation and access
The specialized pool allocator fast-import uses aligned objects on the size of a pointer, which was not sufficient at least on Sparc. Instead, make the alignment for objects of type unitmax_t. Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David S. Miller committed
Dec 14, 2007 at 20:39 UTC
69ae517541ed5ab7d4fdcd8f82a9b8bd949df347
1 file changed
+5
-5
fast-import.c
+5
-5
@@ -196,7 +196,7 @@ struct mem_pool
196
struct mem_pool *next_pool;
197
char *next_free;
198
char *end;
199
- char space[FLEX_ARRAY]; /* more */
199
+ uintmax_t space[FLEX_ARRAY]; /* more */
200
};
201
202
struct atom_str
@@ -534,15 +534,15 @@ static void *pool_alloc(size_t len)
534
total_allocd += sizeof(struct mem_pool) + mem_pool_alloc;
535
p = xmalloc(sizeof(struct mem_pool) + mem_pool_alloc);
536
p->next_pool = mem_pool;
537
- p->next_free = p->space;
537
+ p->next_free = (char *) p->space;
538
p->end = p->next_free + mem_pool_alloc;
539
mem_pool = p;
540
}
541
542
r = p->next_free;
543
- /* round out to a pointer alignment */
544
- if (len & (sizeof(void*) - 1))
545
- len += sizeof(void*) - (len & (sizeof(void*) - 1));
543
+ /* round out to a 'uintmax_t' alignment */
544
+ if (len & (sizeof(uintmax_t) - 1))
545
+ len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));
546
p->next_free += len;
547
return r;
548
}