From c377bb385c3581da86eacaf257f88da50e98dec8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 8 Apr 2020 17:22:22 -0300 Subject: [PATCH] tst_QProcess: create a more reliable crashing Turns out that crashing on purpose is more difficult than it seems. It should be easy, given how often we do it accidentally... Let the null pointer dereferencing be the fall back. Some compilers are too smart for their own good and remove the fault. Instead, let's rely on raise(SIGABRT) on Unix and on the UD2 instruction on Windows. Pick-To: 5.15 Change-Id: Ibdc95e9af7bd456a94ecfffd1603f1c9b73b167d Reviewed-by: Simon Hausmann --- .../io/qprocess/testProcessCrash/main.cpp | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp b/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp index 262db73d72..298a74d2b0 100644 --- a/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp +++ b/tests/auto/corelib/io/qprocess/testProcessCrash/main.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -26,15 +27,33 @@ ** ****************************************************************************/ - -struct Foo +void crashFallback(volatile int *ptr = nullptr) { - int i; -}; + *ptr = 0; +} + +#if defined(_MSC_VER) +# include int main() { - *(volatile char*)0 = 0; - Foo *f = 0; - return f->i; +# if defined(_M_IX86) || defined(_M_X64) + __ud2(); +# endif + + crashFallback(); } +#elif defined(__MINGW32__) +int main() +{ + asm("ud2"); + crashFallback(); +} +#else +# include + +int main() +{ + abort(); +} +#endif