Round out memory pool allocations in fast-import to pointer sizes.
Some architectures (e.g. SPARC) would require that we access pointers only on pointer-sized alignments. So ensure the pool allocator rounds out non-pointer sized allocations to the next pointer so we don't generate bad memory addresses. This could have occurred if we had previously allocated an atom whose string was not a whole multiple of the pointer size, for example. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Aug 24, 2006 at 04:46 UTC
8d8928b0511313ba1740d39c3920f8f12f36a10a
1 file changed
+3
fast-import.c
+3
@@ -342,6 +342,9 @@ static void* pool_alloc(size_t len)
342
}
343
344
r = p->next_free;
345
+ /* round out to a pointer alignment */
346
+ if (len & (sizeof(void*) - 1))
347
+ len += sizeof(void*) - (len & (sizeof(void*) - 1));
348
p->next_free += len;
349
return r;
350
}