mem&util/log: Bugfixes for log utils

- Avoid dereferencing the address of `si_addr` after converting it to `uint64 *`.
- Prohibit to use initialization expressions when using `LOG_XXX_IF`.
- Handle null exception pointer in terminate handler.
This commit is contained in:
Dicot0721
2026-04-03 23:00:34 +08:00
committed by Zangetsu
parent f1ce62af8a
commit e9769da5e8
3 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -583,7 +583,7 @@ static void signal_handler(int sig, siginfo_t *info, void *uct) noexcept {
}
}
LOG_CRITICAL("Unhandled access to {}", log_hex(*reinterpret_cast<uint64_t *>(&info->si_addr)));
LOG_CRITICAL("Unhandled access to 0x{:X}", reinterpret_cast<uintptr_t>(info->si_addr));
raise(SIGTRAP);
return;
}
+1 -5
View File
@@ -36,11 +36,7 @@
#define LOG_ERROR SPDLOG_ERROR
#define LOG_CRITICAL SPDLOG_CRITICAL
#define LOG_IF(log_function, flag, ...) \
do { \
if (flag) \
log_function(__VA_ARGS__); \
} while (0)
#define LOG_IF(log_function, flag, ...) ((flag) ? log_function(__VA_ARGS__) : static_cast<void>(0))
#define LOG_TRACE_IF(flag, ...) LOG_IF(LOG_TRACE, flag, __VA_ARGS__)
#define LOG_DEBUG_IF(flag, ...) LOG_IF(LOG_DEBUG, flag, __VA_ARGS__)
+6 -1
View File
@@ -78,7 +78,12 @@ ExitCode init(const Root &root_paths, bool use_stdout) {
static std::terminate_handler old_terminate = nullptr;
old_terminate = std::set_terminate([]() {
try {
std::rethrow_exception(std::current_exception());
auto eptr = std::current_exception();
if (eptr) {
std::rethrow_exception(eptr);
} else {
LOG_CRITICAL("Unhandled 'std::terminate()' call");
}
} catch (const std::exception &e) {
LOG_CRITICAL("Unhandled C++ exception. {}", e.what());
} catch (...) {