blob: dbf07b80dea248419368e94cce77ea705cdf7f35 [file] [log] [blame]
nethercote57e36b32004-07-10 14:56:28 +00001#include <stdlib.h>
2#include <sys/mman.h>
3#include <stdio.h>
4
5int main(void)
6{
7 void *p;
8
njn2a513bf2005-06-30 02:34:32 +00009 // This is the biggest word-sized signed number. We use a signed number,
10 // even though malloc takes an unsigned SizeT, because the "silly malloc
11 // arg" checking done by memcheck treats the arg like a signed int in
12 // order to detect the passing of a silly size arg like -1.
13 unsigned long size = (~(0UL)) >> 1;
nethercote57e36b32004-07-10 14:56:28 +000014
15 fprintf(stderr, "Attempting too-big malloc()...\n");
16 p = malloc(size); // way too big!
17 if (p)
18 fprintf(stderr, "huge malloc() succeeded??\n");
19
20 fprintf(stderr, "Attempting too-big mmap()...\n");
21 p = mmap( 0, size, PROT_READ|PROT_WRITE|PROT_EXEC,
22 MAP_PRIVATE|MAP_ANON, -1, 0 );
23 if (-1 != (int)p)
24 fprintf(stderr, "huge mmap() succeeded??\n");
25
26 return 0;
27}