-
Notifications
You must be signed in to change notification settings - Fork 0
/
toy_example.c
81 lines (58 loc) · 981 Bytes
/
toy_example.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
69
70
71
72
73
74
75
76
77
78
79
80
81
// A toy example just to produce some stack traces.
#include<stdlib.h>
int f1(int);
char f2(int);
float f3(int);
int (*fp_f1)(int) = f1;
char (*fp_f2)(int) = f2;
float (*fp_f3)(int) = f3;
void malloc_free() {
char* m = malloc(1);
if (m)
free(m);
}
int f1(int depth) {
if (!depth--)
return 0;
if (depth < 3)
malloc_free();
if (depth % 3)
return fp_f3(depth);
if (depth % 2)
return fp_f2(depth);
return fp_f3(depth);
}
char f2(int depth) {
if (!depth--)
return 0;
if (depth < 3)
malloc_free();
if (depth % 3)
return f3(depth);
if (depth % 2)
return f2(depth);
return f3(depth);
}
float f3(int depth) {
if (!depth--)
return 0;
if (depth < 3)
malloc_free();
if (depth % 2)
return fp_f2(depth);
if (depth % 3)
return fp_f3(depth);
return fp_f1(depth);
}
int main() {
f1(32);
f1(31);
f1(30);
f2(32);
f2(31);
f2(30);
f3(32);
f3(31);
f3(30);
return 0;
}