-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmalloc_t.c
68 lines (63 loc) · 1.03 KB
/
malloc_t.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
*Name: malloc_t.c
*Descr: test the malloc function
get the malloc max value supported in current system
*Usage: $gcc malloc_t.c -Wall -o ~/bin/malloc_t
*Author: zuo haitao
*Date: 2008/12/29
*Date: 2011/03/31
*
*/
#include <stdio.h>
#include <stdlib.h>
int Tmalloc(unsigned int unlen);
int main()
{
{
unsigned int i = 0;
for (i = 0; i < 0xffffffff; i++)
{
if (Tmalloc(i) < 0)
{
break;
}
}
}
Tmalloc(100);
Tmalloc(0x10000000);
Tmalloc(0x20000000);
Tmalloc(0x40000000);
Tmalloc(0x60000000);
Tmalloc(0x70000000);
Tmalloc(0x80000000);
Tmalloc(0x90000000);
Tmalloc(0xa0000000);
Tmalloc(0xb0000000);
Tmalloc(0xc0000000);
Tmalloc(0xd0000000);
Tmalloc(0xe0000000);
Tmalloc(0xf0000000);
Tmalloc(0xffffffff);
printf("\n");
return 0;
}
int Tmalloc(unsigned int unlen)
{
int ret = 0;
char* pbuf = 0;
printf("size=%u(0x%x):", unlen, unlen);
fflush(stdout);
pbuf = malloc(unlen);
if (0 == pbuf)
{
ret = -1;
perror("malloc");
}
else
{
ret = 0;
printf("ok\n");
}
free(pbuf);
return ret;
}