Index: libcfa/src/heap.cfa
===================================================================
--- libcfa/src/heap.cfa	(revision dd23e667131b7d56bded56b483f9f83d70d702c5)
+++ libcfa/src/heap.cfa	(revision c1f38e6cb761f0c262410a4cbc49bf127a2918c4)
@@ -10,6 +10,6 @@
 // Created On       : Tue Dec 19 21:58:35 2017
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Aug  5 22:21:27 2020
-// Update Count     : 853
+// Last Modified On : Thu Aug  6 09:08:58 2020
+// Update Count     : 861
 //
 
@@ -95,13 +95,13 @@
 
 #ifdef __CFA_DEBUG__
-static unsigned int allocFree;							// running total of allocations minus frees
+static unsigned int allocUnfreed;						// running total of allocations minus frees
 
 static void prtUnfreed() {
-	if ( allocFree != 0 ) {
+	if ( allocUnfreed != 0 ) {
 		// DO NOT USE STREAMS AS THEY MAY BE UNAVAILABLE AT THIS POINT.
 		char helpText[512];
 		int len = snprintf( helpText, sizeof(helpText), "CFA warning (UNIX pid:%ld) : program terminating with %u(0x%x) bytes of storage allocated but not freed.\n"
 							"Possible cause is unfreed storage allocated by the program or system/library routines called from the program.\n",
-							(long int)getpid(), allocFree, allocFree ); // always print the UNIX pid
+							(long int)getpid(), allocUnfreed, allocUnfreed ); // always print the UNIX pid
 		__cfaabi_bits_write( STDERR_FILENO, helpText, len ); // print debug/nodebug
 	} // if
@@ -110,5 +110,5 @@
 extern "C" {
 	void heapAppStart() {								// called by __cfaabi_appready_startup
-		allocFree = 0;
+		allocUnfreed = 0;
 	} // heapAppStart
 
@@ -226,5 +226,5 @@
 #define __STATISTICS__
 
-// Bucket size must be multiple of 16.
+// Size of array must harmonize with NoBucketSizes and individual bucket sizes must be multiple of 16.
 // Smaller multiples of 16 and powers of 2 are common allocation sizes, so make them generate the minimum required bucket size.
 // malloc(0) returns 0p, so no bucket is necessary for 0 bytes returning an address that can be freed.
@@ -249,5 +249,5 @@
 };
 
-static_assert( NoBucketSizes == sizeof(bucketSizes) / sizeof(bucketSizes[0]), "size of bucket array wrong" );
+static_assert( NoBucketSizes == sizeof(bucketSizes) / sizeof(bucketSizes[0] ), "size of bucket array wrong" );
 
 #ifdef FASTLOOKUP
@@ -267,28 +267,28 @@
 #ifdef __STATISTICS__
 // Heap statistics counters.
+static unsigned int malloc_calls;
+static unsigned long long int malloc_storage;
+static unsigned int aalloc_calls;
+static unsigned long long int aalloc_storage;
+static unsigned int calloc_calls;
+static unsigned long long int calloc_storage;
+static unsigned int memalign_calls;
+static unsigned long long int memalign_storage;
+static unsigned int amemalign_calls;
+static unsigned long long int amemalign_storage;
+static unsigned int cmemalign_calls;
+static unsigned long long int cmemalign_storage;
+static unsigned int resize_calls;
+static unsigned long long int resize_storage;
+static unsigned int realloc_calls;
+static unsigned long long int realloc_storage;
+static unsigned int free_calls;
+static unsigned long long int free_storage;
+static unsigned int mmap_calls;
 static unsigned long long int mmap_storage;
-static unsigned int mmap_calls;
+static unsigned int munmap_calls;
 static unsigned long long int munmap_storage;
-static unsigned int munmap_calls;
+static unsigned int sbrk_calls;
 static unsigned long long int sbrk_storage;
-static unsigned int sbrk_calls;
-static unsigned long long int malloc_storage;
-static unsigned int malloc_calls;
-static unsigned long long int free_storage;
-static unsigned int free_calls;
-static unsigned long long int aalloc_storage;
-static unsigned int aalloc_calls;
-static unsigned long long int calloc_storage;
-static unsigned int calloc_calls;
-static unsigned long long int memalign_storage;
-static unsigned int memalign_calls;
-static unsigned long long int amemalign_storage;
-static unsigned int amemalign_calls;
-static unsigned long long int cmemalign_storage;
-static unsigned int cmemalign_calls;
-static unsigned long long int resize_storage;
-static unsigned int resize_calls;
-static unsigned long long int realloc_storage;
-static unsigned int realloc_calls;
 // Statistics file descriptor (changed by malloc_stats_fd).
 static int statfd = STDERR_FILENO;						// default stderr
@@ -410,11 +410,4 @@
 
 
-// static inline void noMemory() {
-// 	abort( "Heap memory exhausted at %zu bytes.\n"
-// 		   "Possible cause is very large memory allocation and/or large amount of unfreed storage allocated by the program or system/library routines.",
-// 		   ((char *)(sbrk( 0 )) - (char *)(heapManager.heapBegin)) );
-// } // noMemory
-
-
 static inline void checkAlign( size_t alignment ) {
 	if ( alignment < libAlign() || ! libPow2( alignment ) ) {
@@ -441,5 +434,5 @@
 		header = realHeader( header );					// backup from fake to real header
 	} else {
-		alignment = 0;
+		alignment = libAlign();							// => no fake header
 	} // if
 } // fakeHeader
@@ -542,6 +535,6 @@
 		// 	#endif // FASTLOOKUP
 		// 	bsearchl( tsize, freeLists, (size_t)maxBucketsUsed ); // binary search
-		assert( freeElem <= &freeLists[maxBucketsUsed] ); // subscripting error ?
-		assert( tsize <= freeElem->blockSize );			// search failure ?
+		verify( freeElem <= &freeLists[maxBucketsUsed] ); // subscripting error ?
+		verify( tsize <= freeElem->blockSize );			// search failure ?
 		tsize = freeElem->blockSize;					// total space needed for request
 
@@ -599,13 +592,12 @@
 	block->header.kind.real.size = size;				// store allocation size
 	void * addr = &(block->data);						// adjust off header to user bytes
+	verify( ((uintptr_t)addr & (libAlign() - 1)) == 0 ); // minimum alignment ?
 
 	#ifdef __CFA_DEBUG__
-	assert( ((uintptr_t)addr & (libAlign() - 1)) == 0 ); // minimum alignment ?
-	__atomic_add_fetch( &allocFree, tsize, __ATOMIC_SEQ_CST );
+	__atomic_add_fetch( &allocUnfreed, tsize, __ATOMIC_SEQ_CST );
 	if ( traceHeap() ) {
 		enum { BufferSize = 64 };
 		char helpText[BufferSize];
 		int len = snprintf( helpText, BufferSize, "%p = Malloc( %zu ) (allocated %zu)\n", addr, size, tsize );
-		// int len = snprintf( helpText, BufferSize, "Malloc %p %zu\n", addr, size );
 		__cfaabi_bits_write( STDERR_FILENO, helpText, len ); // print debug/nodebug
 	} // if
@@ -659,5 +651,5 @@
 
 	#ifdef __CFA_DEBUG__
-	__atomic_add_fetch( &allocFree, -size, __ATOMIC_SEQ_CST );
+	__atomic_add_fetch( &allocUnfreed, -size, __ATOMIC_SEQ_CST );
 	if ( traceHeap() ) {
 		enum { BufferSize = 64 };
@@ -753,5 +745,5 @@
 	#endif // __CFA_DEBUG__
 
-	//assert( heapManager.heapBegin != 0 );
+	//verify( heapManager.heapBegin != 0 );
 	//heapManager{};
 	if ( heapManager.heapBegin == 0p ) heapManager{};	// sanity check
@@ -991,4 +983,5 @@
 	} // realloc
 
+
 	// Same as malloc() except the memory address is a multiple of alignment, which must be a power of two. (obsolete)
 	void * memalign( size_t alignment, size_t size ) {
@@ -1035,5 +1028,5 @@
 	// free(3).
 	int posix_memalign( void ** memptr, size_t alignment, size_t size ) {
-	  if ( alignment < sizeof(void *) || ! libPow2( alignment ) ) return EINVAL; // check alignment
+	  if ( alignment < libAlign() || ! libPow2( alignment ) ) return EINVAL; // check alignment
 		* memptr = memalign( alignment, size );
 		return 0;
@@ -1194,4 +1187,5 @@
 	} // mallopt
 
+
 	// Attempt to release free memory at the top of the heap (by calling sbrk with a suitable argument).
 	int malloc_trim( size_t ) {
@@ -1237,5 +1231,5 @@
   if ( unlikely( oaddr == 0p ) ) return memalignNoStats( nalign, size );
 
-	if ( unlikely( nalign == 0 ) ) nalign = libAlign();	// reset alignment to minimum
+	if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
 	#ifdef __CFA_DEBUG__
 	else
@@ -1250,5 +1244,5 @@
 
 	if ( oalign <= nalign && (uintptr_t)oaddr % nalign == 0 ) { // <= alignment and new alignment happens to match
-		if ( oalign >= libAlign() ) {					// fake header ?
+		if ( oalign > libAlign() ) {					// fake header ?
 			headerAddr( oaddr )->kind.fake.alignment = nalign | 1; // update alignment (could be the same)
 		} // if
@@ -1267,5 +1261,5 @@
 
 void * realloc( void * oaddr, size_t nalign, size_t size ) {
-	if ( unlikely( nalign == 0 ) ) nalign = libAlign();	// reset alignment to minimum
+	if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
 	#ifdef __CFA_DEBUG__
 	else
@@ -1279,5 +1273,5 @@
 
 	if ( oalign <= nalign && (uintptr_t)oaddr % nalign == 0 ) { // <= alignment and new alignment happens to match
-		if ( oalign >= libAlign() ) {					// fake header ?
+		if ( oalign > libAlign() ) {					// fake header ?
 			headerAddr( oaddr )->kind.fake.alignment = nalign | 1; // update alignment (could be the same)
 		} // if
