*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@978 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
36d26fc08f
commit
5cd99377b5
15 changed files with 227 additions and 75 deletions
97
SWIG/Tools/WAD/Test/debug.c
Normal file
97
SWIG/Tools/WAD/Test/debug.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* debug.c
|
||||
*
|
||||
* This file contains a variety of different programming errors to test with
|
||||
* WAD.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* A simple segmentation fault on an uninitialized pointer */
|
||||
int seg_crash() {
|
||||
int *a = 0;
|
||||
*a = 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Blow the process heap */
|
||||
|
||||
int blowheap_crash() {
|
||||
int i;
|
||||
int *a = (int *) malloc(sizeof(int));
|
||||
|
||||
for (i = 0;; i++) {
|
||||
a[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Buffer overflow crash on the stack */
|
||||
int overflow_crash() {
|
||||
int a[512];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 1024; i++) {
|
||||
a[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* A simple bus error. This might fail silently on certain platforms */
|
||||
int bus_crash() {
|
||||
int b;
|
||||
int *a = &b;
|
||||
a = (int *) ((int) a | 0x1);
|
||||
*a = 3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* An assertion */
|
||||
int abort_crash(int n) {
|
||||
assert(n > 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* A math error (maybe) */
|
||||
int math_crash(int x, int y) {
|
||||
return x/y;
|
||||
}
|
||||
|
||||
|
||||
#ifdef NEED_MAIN
|
||||
|
||||
static const char *usage="\n\
|
||||
Usage: debug type\n\
|
||||
seg - Fail with an uninitialized pointer.\n\
|
||||
bus - Fail with a bus error.\n\
|
||||
abort - Fail with an assertion error.\n\
|
||||
math - Fail with a math error.\n\
|
||||
heap - Blow the process heap.\n\
|
||||
overflow - Buffer overflow on the stack.\n\
|
||||
";
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int n;
|
||||
|
||||
printf("WAD debug program.\n");
|
||||
|
||||
if (argc < 2) {
|
||||
printf("%s\n", usage);
|
||||
exit(0);
|
||||
}
|
||||
if (strcmp(argv[1],"abort") == 0) {
|
||||
abort_crash(-4);
|
||||
} else if (strcmp(argv[1],"seg") ==0) {
|
||||
seg_crash();
|
||||
} else if (strcmp(argv[1],"bus") == 0) {
|
||||
bus_crash();
|
||||
} else if (strcmp(argv[1],"math") == 0) {
|
||||
math_crash(3,0);
|
||||
} else if (strcmp(argv[1],"heap") == 0) {
|
||||
blowheap_crash();
|
||||
} else if (strcmp(argv[1],"overflow") == 0) {
|
||||
overflow_crash();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue