Search
lxdream.org :: lxdream :: r345:7a26147e5dce
lxdream 0.9.1
released Jun 29
Download Now
changeset345:7a26147e5dce
parent344:bac957de4843
child346:9b495cc4db65
authornkeynes
dateWed Jan 31 11:01:58 2007 +0000 (12 years ago)
Add null checks for better error handling
test/testdata.c
1.1 --- a/test/testdata.c Wed Jan 31 11:01:36 2007 +0000
1.2 +++ b/test/testdata.c Wed Jan 31 11:01:58 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: testdata.c,v 1.4 2007-01-06 04:07:43 nkeynes Exp $
1.6 + * $Id: testdata.c,v 1.5 2007-01-31 11:01:58 nkeynes Exp $
1.7 *
1.8 * Test data loader.
1.9 *
1.10 @@ -100,6 +100,10 @@
1.11 *end = '\0';
1.12 current_size = DEFAULT_SIZE;
1.13 test_data_t test = malloc(current_size);
1.14 + if( test == NULL ) {
1.15 + fprintf( stderr, "Memory alloc failed: %d\n", current_size );
1.16 + return NULL;
1.17 + }
1.18 memset( test, 0, current_size );
1.19
1.20 dataptr = (char *)(test+1);
1.21 @@ -130,6 +134,10 @@
1.22 current_end += current_size;
1.23 current_size *= 2;
1.24 current = realloc(current, current_size );
1.25 + if( current == NULL ) {
1.26 + fprintf( stderr, "Memory alloc failed: %d\n", current_size );
1.27 + return NULL;
1.28 + }
1.29 if( last != NULL )
1.30 last->next = current;
1.31 }
1.32 @@ -155,6 +163,10 @@
1.33 current_end += current_size;
1.34 current_size *= 2;
1.35 current = realloc(current, current_size );
1.36 + if( current == NULL ) {
1.37 + fprintf( stderr, "Memory alloc failed: %d\n", current_size );
1.38 + return NULL;
1.39 + }
1.40 memset( current + old_size, 0, old_size );
1.41 if( last != NULL )
1.42 last->next = current;
.