summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/testProcess.c
diff options
context:
space:
mode:
Diffstat (limited to 'Source/kwsys/testProcess.c')
-rw-r--r--Source/kwsys/testProcess.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c
index 877002a..269b84b 100644
--- a/Source/kwsys/testProcess.c
+++ b/Source/kwsys/testProcess.c
@@ -32,7 +32,7 @@
# pragma warn -8060 /* possibly incorrect assignment */
#endif
-#if defined(__BEOS__) && !defined(__ZETA__) && !defined(__HAIKU__)
+#if defined(__BEOS__) && !defined(__ZETA__)
/* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
# include <be/kernel/OS.h>
static inline void testProcess_usleep(unsigned int msec)
@@ -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;