refactor: raise SIGABRT instead of write to null address (#3124)

This commit is contained in:
memchr 2023-08-31 20:52:02 +00:00 committed by GitHub
parent fc0c1896e0
commit 1a13d44d5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -3,6 +3,7 @@
#include "helpers/MiscFunctions.hpp" #include "helpers/MiscFunctions.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include <cmath> #include <cmath>
#include <csignal>
#include <utility> #include <utility>
#ifndef NDEBUG #ifndef NDEBUG
@ -57,9 +58,9 @@
if (!(expr)) { \ if (!(expr)) { \
Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n%s\n\nat: line %d in %s", \ Debug::log(CRIT, "\n==========================================================================================\nASSERTION FAILED! \n\n%s\n\nat: line %d in %s", \
getFormat(reason, ##__VA_ARGS__).c_str(), __LINE__, \ getFormat(reason, ##__VA_ARGS__).c_str(), __LINE__, \
([]() constexpr->std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \ ([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })().c_str()); \
printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \ printf("Assertion failed! See the log in /tmp/hypr/hyprland.log for more info."); \
*((int*)nullptr) = 1; /* so that we crash and get a coredump */ \ raise(SIGABRT); \
} }
#else #else
#define RASSERT(expr, reason, ...) #define RASSERT(expr, reason, ...)
@ -71,7 +72,7 @@
#define UNREACHABLE() \ #define UNREACHABLE() \
{ \ { \
Debug::log(CRIT, "\n\nMEMORY CORRUPTED: Unreachable failed! (Reached an unreachable position, memory corruption!!!)"); \ Debug::log(CRIT, "\n\nMEMORY CORRUPTED: Unreachable failed! (Reached an unreachable position, memory corruption!!!)"); \
*((int*)nullptr) = 1; \ raise(SIGABRT); \
} }
#else #else
#define UNREACHABLE() std::unreachable(); #define UNREACHABLE() std::unreachable();

View file

@ -1973,7 +1973,7 @@ static int handleCrashLoop(void* data) {
g_pHyprRenderer->m_fCrashingDistort += 0.5f; g_pHyprRenderer->m_fCrashingDistort += 0.5f;
if (g_pHyprRenderer->m_fCrashingDistort >= 5.5f) if (g_pHyprRenderer->m_fCrashingDistort >= 5.5f)
*((int*)nullptr) = 1337; raise(SIGABRT);
wl_event_source_timer_update(g_pHyprRenderer->m_pCrashingLoop, 1000); wl_event_source_timer_update(g_pHyprRenderer->m_pCrashingLoop, 1000);