~ubuntu-branches/ubuntu/quantal/libgc/quantal

« back to all changes in this revision

Viewing changes to tests/huge_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-19 12:19:56 UTC
  • mfrom: (1.3.2 upstream) (0.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110219121956-67rb69xlt5nud3v2
Tags: 1:7.1-5
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <limits.h>
 
3
#include <stdio.h>
 
4
#include <gc.h>
 
5
 
 
6
/*
 
7
 * Check that very large allocation requests fail.  "Success" would usually
 
8
 * indicate that the the size was somehow converted to a negative
 
9
 * number.  Clients shouldn't do this, but we should fail in the
 
10
 * expected manner.
 
11
 */
 
12
 
 
13
 
 
14
main()
 
15
{
 
16
    GC_INIT();
 
17
 
 
18
    GC_set_max_heap_size(100*1024*1024);
 
19
        /* Otherwise heap expansion aborts when deallocating large block. */
 
20
        /* That's OK.  We test this corner case mostly to make sure that  */
 
21
        /* it fails predictably.                                          */
 
22
    GC_expand_hp(1024*1024*5);
 
23
    if (sizeof(long) == sizeof(void *)) {
 
24
        void *r = GC_MALLOC(LONG_MAX-1024);
 
25
        if (0 != r) {
 
26
            fprintf(stderr,
 
27
                    "Size LONG_MAX-1024 allocation unexpectedly succeeded\n");
 
28
            exit(1);
 
29
        }
 
30
        r = GC_MALLOC(LONG_MAX);
 
31
        if (0 != r) {
 
32
            fprintf(stderr,
 
33
                    "Size LONG_MAX allocation unexpectedly succeeded\n");
 
34
            exit(1);
 
35
        }
 
36
        r = GC_MALLOC((size_t)LONG_MAX + 1024);
 
37
        if (0 != r) {
 
38
            fprintf(stderr,
 
39
                    "Size LONG_MAX+1024 allocation unexpectedly succeeded\n");
 
40
            exit(1);
 
41
        }
 
42
    }
 
43
    return 0;
 
44
}
 
45