if ( ( pt = malloc( size ) ) == NULL )
{
- fprintf( stderr, "ERROR: Could not allocate %ld byte(s): %s\n", size, strerror( errno ) );
+ fprintf( stderr, "ERROR: Could not allocate %zu byte(s): %s\n", size, strerror( errno ) );
abort();
}
{
/* Martin A. Hansen, May 2008 */
+ /* Unit test done.*/
+
/* Resize an allocated chunk of memory for a given pointer and new size. */
void *pt_new;
- if ( size == 0 ) {
- die( "could not re-allocate 0 bytes of memory." );
- } else if ( ( pt_new = realloc( pt, size ) ) == NULL ) {
- die( "could not re-allocate memory." );
+ assert( size > 0 );
+
+ if ( ( pt_new = realloc( pt, size ) ) == NULL )
+ {
+ fprintf( stderr, "ERROR: Could not re-allocate %zu byte(s)\n", size );
+ abort();
}
return pt_new;
{
/* Martin A. Hansen, May 2008 */
+ /* Unit test done.*/
+
/* Resize an allocated chunk of memory for a given pointer and zero any extra memory. */
void *pt_new;
{
/* Martin A. Hansen, June 2008 */
+ /* Unit test done.*/
+
/* Clone a structure in memory and return a pointer to the clone. */
void *new_pt;
+ assert( size > 0 );
+
new_pt = mem_get( size );
memcpy( new_pt, old_pt, size );
}
-void mem_free( void *pt )
+void mem_free( void **ppt )
{
/* Martin A. Hansen, May 2008 */
- /* Free memory from a given pointer. */
-
- if ( pt != NULL )
- {
- free( pt );
-
- pt = NULL;
- }
-}
-
-
-void mem_free_zero( void *pt )
-{
- /* Martin A. Hansen, July 2008 */
+ /* Unit test done.*/
- /* Zero and then free memory from a given pointer. */
+ /* Free memory from a given pointer. */
- if ( pt != NULL )
- {
- MEM_ZERO( pt );
- free( pt );
+ free( *ppt );
- pt = NULL;
- }
+ *ppt = NULL;
}