diff options
author | Brad King <brad.king@kitware.com> | 2012-12-19 13:09:36 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2012-12-19 13:09:36 (GMT) |
commit | e33fa5b67880e47fb350d5545a5ba04b8d6f3eb3 (patch) | |
tree | 1c08689b76eaf6228cd7fc946e12334350326f9e /Source/kwsys/testProcess.c | |
parent | 5ac16ea6e4ddb086d48c97fa4f58543284ec3305 (diff) | |
parent | a0f91f1daa7765066a784e4479da7e231374a065 (diff) | |
download | CMake-e33fa5b67880e47fb350d5545a5ba04b8d6f3eb3.zip CMake-e33fa5b67880e47fb350d5545a5ba04b8d6f3eb3.tar.gz CMake-e33fa5b67880e47fb350d5545a5ba04b8d6f3eb3.tar.bz2 |
Merge branch 'upstream-kwsys' into update-kwsys
Diffstat (limited to 'Source/kwsys/testProcess.c')
-rw-r--r-- | Source/kwsys/testProcess.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c index 877002a..ec561ea 100644 --- a/Source/kwsys/testProcess.c +++ b/Source/kwsys/testProcess.c @@ -82,6 +82,14 @@ int test3(int argc, const char* argv[]) int test4(int argc, const char* argv[]) { + /* Prepare a pointer to an invalid address. Don't use null, because + dereferencing null is undefined behaviour and compilers are free to + do whatever they want. ex: Clang will warn at compile time, or even + optimize away the write. We hope to 'outsmart' them by using + 'volatile' and a slightly larger address, based on a runtime value. */ + volatile int* invalidAddress = 0; + invalidAddress += argc?1:2; + #if defined(_WIN32) /* Avoid error diagnostic popups since we are crashing on purpose. */ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); @@ -94,11 +102,8 @@ int test4(int argc, const char* argv[]) fprintf(stderr, "Output before crash on stderr from crash test.\n"); fflush(stdout); fflush(stderr); -#if defined(__clang__) - *(int*)1 = 0; /* Clang warns about 0-ptr; undefined behavior. */ -#else - *(int*)0 = 0; -#endif + /* Provoke deliberate crash by writing to the invalid address. */ + *invalidAddress = 0; fprintf(stdout, "Output after crash on stdout from crash test.\n"); fprintf(stderr, "Output after crash on stderr from crash test.\n"); return 0; |