Align smallAllocs to the native pointer size.

This commit is contained in:
Ryan C. Gordon 2012-03-09 22:27:51 -05:00
parent a0b21c9ae9
commit 9dceda3d9f
1 changed files with 6 additions and 6 deletions

View File

@ -2748,17 +2748,17 @@ static void setDefaultAllocator(void)
void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len) void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len)
{ {
const char useHeap = ((ptr == NULL) ? 1 : 0); void *useHeap = ((ptr == NULL) ? ((void *) 1) : ((void *) 0));
if (useHeap) /* too large for stack allocation or alloca() failed. */ if (useHeap) /* too large for stack allocation or alloca() failed. */
ptr = allocator.Malloc(len+1); ptr = allocator.Malloc(len+sizeof (void *));
if (ptr != NULL) if (ptr != NULL)
{ {
char *retval = (char *) ptr; void **retval = (void **) ptr;
/*printf("%s alloc'd (%d) bytes at (%p).\n", /*printf("%s alloc'd (%d) bytes at (%p).\n",
useHeap ? "heap" : "stack", (int) len, ptr);*/ useHeap ? "heap" : "stack", (int) len, ptr);*/
*retval = useHeap; *retval = useHeap;
return (retval + 1); return retval + 1;
} /* if */ } /* if */
return NULL; /* allocation failed. */ return NULL; /* allocation failed. */
@ -2769,8 +2769,8 @@ void __PHYSFS_smallFree(void *ptr)
{ {
if (ptr != NULL) if (ptr != NULL)
{ {
char *block = ((char *) ptr) - 1; void **block = ((void **) ptr) - 1;
const char useHeap = *block; const int useHeap = (*block != 0);
if (useHeap) if (useHeap)
allocator.Free(block); allocator.Free(block);
/*printf("%s free'd (%p).\n", useHeap ? "heap" : "stack", block);*/ /*printf("%s free'd (%p).\n", useHeap ? "heap" : "stack", block);*/