/tags/rel-1-3-15/SWIG/Tools/WAD/Wad/debug.c
C | 98 lines | 85 code | 13 blank | 0 comment | 25 complexity | aa84598c712187e333139a5a9dfc87a6 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1#include <stdio.h>
2#include <string.h>
3#include "wad.h"
4#include <assert.h>
5
6typedef struct Foo {
7 double a;
8 double b;
9 float c;
10} Foo;
11
12static int type_crash(int n, short m, char c, double x, float y, Foo f, void *ptr) {
13 int *a = 0;
14 *a = 3;
15 return 1;
16}
17static int seg_crash(int n, double x,
18 float y) {
19 int *a = 0;
20 if (n > 0) seg_crash(n-1,x,y);
21 *a = 3;
22 return 1;
23}
24
25int bus_crash(int n) {
26 int b;
27 int *a = &b;
28 a = (int *) ((int) a | 0x1);
29 if (n > 0) bus_crash(n-1);
30 *a = 3;
31 printf("well, well, well.\n");
32 return 1;
33}
34
35int abort_crash(int n) {
36 assert(n > 0);
37 abort_crash(n-1);
38 return 1;
39}
40
41double double_crash(double a, double b) {
42 double *c;
43 *c = a+b;
44 return *c;
45}
46
47int math_crash(int x, int y) {
48 return x/y;
49}
50
51int call_func(int n, int (*f)(int)) {
52
53 int ret;
54 ret = (*f)(n);
55 if (ret <= 0) {
56 printf("An error occurred!\n");
57 }
58 return 0;
59}
60
61static int multi(char a, short b, int c, double d) {
62 a = 'x';
63 b = 15236;
64 c = 12345678;
65 d = 3.14159;
66 return c;
67}
68
69static int test(int x, int (*f)(int)) {
70 return (*f)(-x);
71}
72
73int main(int argc, char **argv) {
74 int n;
75 int (*f)(int);
76 Foo foo = { 3.14, 28.18, 1.0 };
77
78 printf("starting.\n");
79
80 if (strcmp(argv[1],"abort") == 0) {
81 abort_crash(0);
82 } else if (strcmp(argv[1],"seg") ==0) {
83 seg_crash(0,1,2);
84 } else if (strcmp(argv[1],"bus") == 0) {
85 bus_crash(0);
86 } else if (strcmp(argv[1],"ret") == 0) {
87 call_func(4,abort_crash);
88 } else if (strcmp(argv[1],"test") == 0) {
89 test(-1000,abort_crash);
90 } else if (strcmp(argv[1],"double") == 0) {
91 double_crash(3.14159,2.1828);
92 } else if (strcmp(argv[1],"math") == 0) {
93 math_crash(3,0);
94 } else if (strcmp(argv[1],"type") == 0) {
95 type_crash(34,42,17, 3.14159, 2.1828, foo, &foo);
96 }
97 multi(3,5,10,3.14);
98}