Index: libcfa/src/stdlib.hfa
===================================================================
--- libcfa/src/stdlib.hfa	(revision e310238dc115b8a59b4870d91acdf4486823fb2f)
+++ libcfa/src/stdlib.hfa	(revision b89c7c2551f7610cc566e97aacc92b8223615ab3)
@@ -9,7 +9,7 @@
 // Author           : Peter A. Buhr
 // Created On       : Thu Jan 28 17:12:35 2016
-// Last Modified By : Andrew Beach
-// Last Modified On : Tue Jun  2 16:47:00 2020
-// Update Count     : 451
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sun Jul 19 18:29:34 2020
+// Update Count     : 463
 //
 
@@ -57,9 +57,19 @@
 	} // calloc
 
-	T * resize( T * ptr, size_t size ) {				// CFA realloc, eliminate return-type cast
-		return (T *)(void *)resize( (void *)ptr, size ); // C realloc
+	T * resize( T * ptr, size_t size ) {				// CFA resize, eliminate return-type cast
+		if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { // special cases
+			if ( unlikely( size == 0 ) ) free( ptr );
+			if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
+			else return (T *)memalign( _Alignof(T), sizeof(T) );
+		} // if
+		return (T *)(void *)resize( (void *)ptr, size ); // CFA resize
 	} // resize
 
 	T * realloc( T * ptr, size_t size ) {				// CFA realloc, eliminate return-type cast
+		if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { // special cases
+			if ( unlikely( size == 0 ) ) free( ptr );
+			if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
+			else return (T *)memalign( _Alignof(T), sizeof(T) );
+		} // if
 		return (T *)(void *)realloc( (void *)ptr, size ); // C realloc
 	} // realloc
@@ -118,8 +128,8 @@
 
 	T * alloc( T ptr[], size_t dim, bool copy = true ) {
-		if ( copy ) {									// realloc
-			return (T *)(void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
+		if ( copy ) {
+			return realloc( ptr, dim * sizeof(T) );		// CFA realloc
 		} else {
-			return resize( ptr, dim * sizeof(T) );		// resize
+			return resize( ptr, dim * sizeof(T) );		// CFA resize
 		} // if
 	} // alloc
@@ -146,9 +156,26 @@
 		return (T *)memcpy( (T *)alloc( dim ), fill, dim * sizeof(T) ); // initialize with fill value
 	} // alloc
-} // distribution
-
-forall( dtype T | sized(T) ) {
-	T * alloc_set( T ptr[], size_t dim, char fill );	// realloc array with fill
-	T * alloc_set( T ptr[], size_t dim, T fill );		// realloc array with fill
+
+	T * alloc_set( T ptr[], size_t dim, char fill ) {	// realloc array with fill
+		size_t osize = malloc_size( ptr );				// current allocation
+		T * nptr = realloc( ptr, dim * sizeof(T) );		// CFA realloc
+		size_t nsize = malloc_size( nptr );				// new allocation
+		if ( nsize > osize ) {							// larger ?
+			memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
+		} // if
+		return (T *)nptr;
+	} // alloc_set
+
+	T * alloc_set( T ptr[], size_t dim, T & fill ) {	// realloc array with fill
+		size_t odim = malloc_size( ptr ) / sizeof(T);	// current allocation
+		T * nptr = realloc( ptr, dim * sizeof(T) );		// CFA realloc
+		size_t ndim = malloc_size( nptr ) / sizeof(T);	// new allocation
+		if ( ndim > odim ) {							// larger ?
+			for ( i; odim ~ ndim ) {
+				memcpy( &nptr[i], &fill, sizeof(T) );	// initialize with fill value
+			} // for
+		} // if
+		return (T *)nptr;
+	} // alloc_align_set
 } // distribution
 
@@ -196,11 +223,26 @@
 		return (T *)memcpy( (T *)alloc_align( align, dim ), fill, dim * sizeof(T) );
 	} // alloc_align
-} // distribution
-
-forall( dtype T | sized(T) ) {
-	T * alloc_align_set( T ptr[], size_t align, char fill ); // aligned realloc with fill
-	T * alloc_align_set( T ptr[], size_t align, T fill ); // aligned realloc with fill
-	T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); // aligned realloc array with fill
-	T * alloc_align_set( T ptr[], size_t align, size_t dim, T fill ); // aligned realloc array with fill
+
+	T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ) {
+		size_t osize = malloc_size( ptr );				// current allocation
+		T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc
+		size_t nsize = malloc_size( nptr );				// new allocation
+		if ( nsize > osize ) {							// larger ?
+			memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
+		} // if
+		return (T *)nptr;
+	} // alloc_align_set
+
+	T * alloc_align_set( T ptr[], size_t align, size_t dim, T & fill ) {
+		size_t odim = malloc_size( ptr ) / sizeof(T);	// current allocation
+		T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc
+		size_t ndim = malloc_size( nptr );				// new allocation
+		if ( ndim > odim ) {							// larger ?
+			for ( i; odim ~ ndim ) {
+				memcpy( &nptr[i], &fill, sizeof(T) );	// initialize with fill value
+			} // for
+		} // if
+		return (T *)nptr;
+	} // alloc_align_set
 } // distribution
 
