int RecurseAlloc() { int *pi = new int[BIG_NUMBER]; pi; RecurseAlloc(); return 0; }
int crEmulateCrash(unsigned ExceptionType) { switch(ExceptionType) { case CR_SEH_EXCEPTION: { // Access violation int *p = 0; #pragma warning(disable : 6011) // warning C6011: Dereferencing NULL pointer 'p' *p = 0; #pragma warning(default : 6011) } break; case CR_CPP_TERMINATE_CALL: { // Call terminate terminate(); } break; case CR_CPP_UNEXPECTED_CALL: { // Call unexpected unexpected(); } break; case CR_CPP_PURE_CALL: { // pure virtual method call CDerived derived; } break; case CR_CPP_SECURITY_ERROR: { // Cause buffer overrun (/GS compiler option) // declare buffer that is bigger than expected char large_buffer[] = "This string is longer than 10 characters!!"; test_buffer_overrun(large_buffer); } break; case CR_CPP_INVALID_PARAMETER: { char* formatString; // Call printf_s with invalid parameters. formatString = NULL; // warning C6387: 'argument 1' might be '0': this does not adhere to the specification for the function 'printf' #pragma warning(disable : 6387) printf(formatString); #pragma warning(default : 6387) } break; case CR_CPP_NEW_OPERATOR_ERROR: { // Cause memory allocation error RecurseAlloc(); } break; case CR_CPP_SIGABRT: { // Call abort abort(); } break; case CR_CPP_SIGFPE: { // floating point exception ( /fp:except compiler option) sigfpe_test(); return 1; } case CR_CPP_SIGILL: { int result = raise(SIGILL); assert(result==0); return result; } case CR_CPP_SIGINT: { int result = raise(SIGINT); assert(result==0); return result; } case CR_CPP_SIGSEGV: { int result = raise(SIGSEGV); assert(result==0); return result; } case CR_CPP_SIGTERM: { int result = raise(SIGTERM); assert(result==0); return result; } case CR_NONCONTINUABLE_EXCEPTION: { // Raise noncontinuable software exception RaiseException(123, EXCEPTION_NONCONTINUABLE, 0, NULL); } break; case CR_THROW: { // Throw typed C++ exception. throw 13; } break; case CR_STACK_OVERFLOW: { // Infinite recursion and stack overflow. CauseStackOverflow(); } default: break; } return 1; }