diff --git a/libcxxabi/src/fallback_malloc.cpp b/libcxxabi/src/fallback_malloc.cpp --- a/libcxxabi/src/fallback_malloc.cpp +++ b/libcxxabi/src/fallback_malloc.cpp @@ -60,8 +60,21 @@ static const size_t HEAP_SIZE = 512; char heap[HEAP_SIZE] __attribute__((aligned)); -typedef unsigned short heap_offset; -typedef unsigned short heap_size; +template +struct half_size_uint; + +template<> +struct half_size_uint<8> { + typedef unsigned int type; +}; + +template<> +struct half_size_uint<4> { + typedef unsigned short type; +}; + +typedef half_size_uint::type heap_offset; +typedef half_size_uint::type heap_size; struct heap_node { heap_offset next_node; // offset into heap diff --git a/libcxxabi/test/test_fallback_malloc.pass.cpp b/libcxxabi/test/test_fallback_malloc.pass.cpp --- a/libcxxabi/test/test_fallback_malloc.pass.cpp +++ b/libcxxabi/test/test_fallback_malloc.pass.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include #include #include @@ -179,6 +180,8 @@ std::printf("fallback_malloc ( 32 ) --> %lu\n", (unsigned long) (p - heap)); if ( !is_fallback_ptr ( p )) std::printf("### p is not a fallback pointer!!\n"); + assert(((intptr_t)p % sizeof(void *) == 0) + && "p must be aligned as sizeof(void*)"); print_free_list (); fallback_free ( p );