PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/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. typedef struct Foo {
  6. double a;
  7. double b;
  8. float c;
  9. } Foo;
  10. static int type_crash(int n, short m, char c, double x, float y, Foo f, void *ptr) {
  11. int *a = 0;
  12. *a = 3;
  13. return 1;
  14. }
  15. static int seg_crash(int n, double x,
  16. float y) {
  17. int *a = 0;
  18. if (n > 0) seg_crash(n-1,x,y);
  19. *a = 3;
  20. return 1;
  21. }
  22. int bus_crash(int n) {
  23. int b;
  24. int *a = &b;
  25. a = (int *) ((int) a | 0x1);
  26. if (n > 0) bus_crash(n-1);
  27. *a = 3;
  28. printf("well, well, well.\n");
  29. return 1;
  30. }
  31. int abort_crash(int n) {
  32. assert(n > 0);
  33. abort_crash(n-1);
  34. return 1;
  35. }
  36. double double_crash(double a, double b) {
  37. double *c;
  38. *c = a+b;
  39. return *c;
  40. }
  41. int math_crash(int x, int y) {
  42. return x/y;
  43. }
  44. int call_func(int n, int (*f)(int)) {
  45. int ret;
  46. ret = (*f)(n);
  47. if (ret <= 0) {
  48. printf("An error occurred!\n");
  49. }
  50. return 0;
  51. }
  52. static int multi(char a, short b, int c, double d) {
  53. a = 'x';
  54. b = 15236;
  55. c = 12345678;
  56. d = 3.14159;
  57. return c;
  58. }
  59. static int test(int x, int (*f)(int)) {
  60. return (*f)(-x);
  61. }
  62. int main(int argc, char **argv) {
  63. int n;
  64. int (*f)(int);
  65. Foo foo = { 3.14, 28.18, 1.0 };
  66. printf("starting.\n");
  67. if (strcmp(argv[1],"abort") == 0) {
  68. abort_crash(0);
  69. } else if (strcmp(argv[1],"seg") ==0) {
  70. seg_crash(0,1,2);
  71. } else if (strcmp(argv[1],"bus") == 0) {
  72. bus_crash(0);
  73. } else if (strcmp(argv[1],"ret") == 0) {
  74. call_func(4,abort_crash);
  75. } else if (strcmp(argv[1],"test") == 0) {
  76. test(-1000,abort_crash);
  77. } else if (strcmp(argv[1],"double") == 0) {
  78. double_crash(3.14159,2.1828);
  79. } else if (strcmp(argv[1],"math") == 0) {
  80. math_crash(3,0);
  81. } else if (strcmp(argv[1],"type") == 0) {
  82. type_crash(34,42,17, 3.14159, 2.1828, foo, &foo);
  83. }
  84. multi(3,5,10,3.14);
  85. }