From 2ad5fd36fb0b77040113e93323911fbd5c3ccb49 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 16 Nov 2021 19:22:40 +0100 Subject: Rework FatalSignalHandler to use ranged-for loops over signals Shrinks the const array by one zero-terminator and makes the code accessing it read more gracefully. Change-Id: I4034116a83ff3cd05ea0feb0ce8a4340c54a9faa Reviewed-by: Thiago Macieira --- src/testlib/qtestcase.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 79191861b1..4cb9067c69 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1670,7 +1670,7 @@ public: sigemptyset(&handledSignals); const int fatalSignals[] = { - SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 }; + SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM }; struct sigaction act; memset(&act, 0, sizeof(act)); @@ -1703,8 +1703,8 @@ public: // Block all fatal signals in our signal handler so we don't try to close // the testlog twice. sigemptyset(&act.sa_mask); - for (int i = 0; fatalSignals[i]; ++i) - sigaddset(&act.sa_mask, fatalSignals[i]); + for (int sig : fatalSignals) + sigaddset(&act.sa_mask, sig); // The destructor can only restore SIG_DFL, so only register for signals // that had default handling previously. @@ -1720,14 +1720,14 @@ public: }; struct sigaction oldact; - for (int i = 0; fatalSignals[i]; ++i) { + for (int sig : fatalSignals) { // Registering reveals the existing handler: - if (sigaction(fatalSignals[i], &act, &oldact)) + if (sigaction(sig, &act, &oldact)) continue; // Failed to set our handler; nothing to restore. if (isDefaultHandler(oldact)) - sigaddset(&handledSignals, fatalSignals[i]); + sigaddset(&handledSignals, sig); else // Restore non-default handler: - sigaction(fatalSignals[i], &oldact, nullptr); + sigaction(sig, &oldact, nullptr); } #endif // defined(Q_OS_UNIX) && !defined(Q_OS_WASM) } -- cgit v1.2.3