diff options
author | David Schleef <ds@schleef.org> | 2001-07-13 03:08:08 +0000 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2001-07-13 03:08:08 +0000 |
commit | 4a8c7f58977103dec5b5ca329b4149bcdfc0d4b3 (patch) | |
tree | 2a7fe58b063071acdb4fab572d186f0d37af1ace | |
parent | ffc7bb39cce77ae6243aa903f0cc1a96ab42bce8 (diff) |
Add test for proper realloc() behavior.
-rw-r--r-- | test/malloc/malloc.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/test/malloc/malloc.c b/test/malloc/malloc.c index 698ab5e70..ac40ec6a2 100644 --- a/test/malloc/malloc.c +++ b/test/malloc/malloc.c @@ -10,8 +10,17 @@ #define random_size() (random()%MAX_SIZE) #define random_ptr() (random()%N_PTRS) +void test1(void); +void test2(void); + int main(int argc,char *argv[]) { + test1(); + test2(); +} + +void test1(void) +{ void **ptrs; int i,j; int size; @@ -37,7 +46,24 @@ int main(int argc,char *argv[]) for(i=0;i<N_PTRS;i++){ free(ptrs[i]); } +} - return 0; +void test2(void) +{ + void *ptr = NULL; + + ptr = realloc(ptr,100); + if(!ptr){ + printf("couldn't realloc() a NULL pointer\n"); + }else{ + free(ptr); + } + + ptr = malloc(100); + ptr = realloc(ptr, 0); + if(ptr){ + printf("realloc(,0) failed\n"); + free(ptr); + } } |