Add tests for calloc()

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
This commit is contained in:
ohnx 2017-12-12 05:22:52 +00:00 committed by Augustin Cavalier
parent 8a4744fbe4
commit 3934b3e6cc
2 changed files with 36 additions and 0 deletions

View File

@ -10,6 +10,7 @@ TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)
SimpleTest abort_test : abort_test.cpp ;
SimpleTest SyslogTest : SyslogTest.cpp ;
SimpleTest brk_test : brk_test.c ;
SimpleTest calloc_test : calloc_test.c ;
SimpleTest clearenv : clearenv.cpp ;
SimpleTest dirent_test : dirent_test.cpp ;
SimpleTest flock_test : flock_test.cpp ;

View File

@ -0,0 +1,35 @@
/*
* Copyright 2017, ohnx, me@masonx.ca.
* Distributed under the terms of the CC0 License.
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
int
main()
{
void *ptr;
printf("Testing calloc(SIZE_MAX, SIZE_MAX)... ");
if (calloc(SIZE_MAX, SIZE_MAX) != NULL) {
printf("fail!\n");
}
printf("pass!\n");
printf("Testing calloc(0, 0)... ");
/* issues with calloc() here will throw a panic */
ptr = calloc(0, 0);
/* free the value, since calloc() should return a free() able pointer */
free(ptr);
printf("pass!\n");
printf("Testing calloc(-1, -1)... ");
if (calloc(-1, -1) != NULL) {
printf("")
}
printf("pass!\n");
return 0;
}