summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2011-09-30 14:17:31 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-09-30 14:18:37 +0200
commit016fa329ce07d0ca55523be0dbe4241275483caf (patch)
treeaa9c5a1399fb9f65b00d7d7ae3566946d5510074 /tests
parentb0e50c95c8f23e2cb8e0c315fa6a17dbcbd17aab (diff)
tests: Add missing checks of GC_malloc result (for out-of-memory)
* tests/test.c (mktree): Insert CHECK_OUT_OF_MEMORY to report mktree() out-of-memory failures. * tests/trace_test.c (mktree): Test whether GC_MALLOC_ATOMIC returns NULL (exit with an error code and the appropriate message printed in this case).
Diffstat (limited to 'tests')
-rw-r--r--tests/test.c5
-rw-r--r--tests/trace_test.c5
2 files changed, 9 insertions, 1 deletions
diff --git a/tests/test.c b/tests/test.c
index e2f7a01..fb49c95 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -726,8 +726,11 @@ tn * mktree(int n)
result -> lchild = mktree(n-1);
result -> rchild = mktree(n-1);
if (counter++ % 17 == 0 && n >= 2) {
- tn * tmp = result -> lchild -> rchild;
+ tn * tmp;
+ CHECK_OUT_OF_MEMORY(result->lchild);
+ tmp = result -> lchild -> rchild;
+ CHECK_OUT_OF_MEMORY(result->rchild);
result -> lchild -> rchild = result -> rchild -> lchild;
result -> rchild -> lchild = tmp;
}
diff --git a/tests/trace_test.c b/tests/trace_test.c
index bb8b813..923e0f8 100644
--- a/tests/trace_test.c
+++ b/tests/trace_test.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#ifndef GC_DEBUG
# define GC_DEBUG
@@ -16,6 +17,10 @@ struct treenode * mktree(int i) {
struct treenode * r = GC_MALLOC(sizeof(struct treenode));
if (0 == i) return 0;
if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode));
+ if (r == NULL) {
+ printf("Out of memory\n");
+ exit(1);
+ }
r -> x = mktree(i-1);
r -> y = mktree(i-1);
return r;