add check to malloc calls

This commit is contained in:
2018-11-14 16:21:26 -03:00
parent fa78806865
commit 1024e6f8dc
3 changed files with 32 additions and 0 deletions

View File

@@ -57,8 +57,20 @@ int main(int argc, char **argv) {
int failed = 0;
test_case = malloc(sizeof(int) * n);
if (test_case == NULL) {
fprintf("Error: Out of heap space!\n");
exit(1);
}
qarray = malloc(sizeof(int) * n);
if (qarray == NULL) {
fprintf("Error: Out of heap space!\n");
exit(1);
}
test_array = malloc(sizeof(int) * n);
if (test_array == NULL) {
fprintf("Error: Out of heap space!\n");
exit(1);
}
atexit(cleanup);