X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=hs-boehmgc.git;a=blobdiff_plain;f=gc-7.2%2Ftests%2Fhuge_test.c;fp=gc-7.2%2Ftests%2Fhuge_test.c;h=bde9836d5a8c48c02f9c68c925932739cdd1e255;hp=0000000000000000000000000000000000000000;hb=324587ba93dc77f37406d41fd2a20d0e0d94fb1d;hpb=2a4ea609491b225a1ceb06da70396e93916f137a diff --git a/gc-7.2/tests/huge_test.c b/gc-7.2/tests/huge_test.c new file mode 100644 index 0000000..bde9836 --- /dev/null +++ b/gc-7.2/tests/huge_test.c @@ -0,0 +1,52 @@ + +#include +#include +#include + +#ifndef GC_IGNORE_WARN + /* Ignore misleading "Out of Memory!" warning (which is printed on */ + /* every GC_MALLOC(LONG_MAX) call) by defining this macro before */ + /* "gc.h" inclusion. */ +# define GC_IGNORE_WARN +#endif + +#include "gc.h" + +/* + * Check that very large allocation requests fail. "Success" would usually + * indicate that the size was somehow converted to a negative + * number. Clients shouldn't do this, but we should fail in the + * expected manner. + */ + +int main(void) +{ + GC_INIT(); + + GC_set_max_heap_size(100*1024*1024); + /* Otherwise heap expansion aborts when deallocating large block. */ + /* That's OK. We test this corner case mostly to make sure that */ + /* it fails predictably. */ + GC_expand_hp(1024*1024*5); + if (sizeof(long) == sizeof(void *)) { + void *r = GC_MALLOC(LONG_MAX-1024); + if (0 != r) { + fprintf(stderr, + "Size LONG_MAX-1024 allocation unexpectedly succeeded\n"); + exit(1); + } + r = GC_MALLOC(LONG_MAX); + if (0 != r) { + fprintf(stderr, + "Size LONG_MAX allocation unexpectedly succeeded\n"); + exit(1); + } + r = GC_MALLOC((size_t)LONG_MAX + 1024); + if (0 != r) { + fprintf(stderr, + "Size LONG_MAX+1024 allocation unexpectedly succeeded\n"); + exit(1); + } + } + return 0; +}