From e289380c399eef725bbcbac071ed66ded21770e8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 9 May 2025 19:33:01 +0200 Subject: [PATCH] fix: Crash when selecting invalid time_t --- .../builtin/source/content/data_inspector.cpp | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/builtin/source/content/data_inspector.cpp b/plugins/builtin/source/content/data_inspector.cpp index 470f738d7..515805c53 100644 --- a/plugins/builtin/source/content/data_inspector.cpp +++ b/plugins/builtin/source/content/data_inspector.cpp @@ -625,7 +625,12 @@ namespace hex::plugin::builtin { std::string value; try { - value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", *std::localtime(&endianAdjustedTime)); + auto time = std::localtime(&endianAdjustedTime); + if (time == nullptr) { + value = "Invalid"; + } else { + value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", *time); + } } catch (fmt::format_error &) { value = "Invalid"; } @@ -640,7 +645,12 @@ namespace hex::plugin::builtin { std::string value; try { - value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", *std::localtime(&endianAdjustedTime)); + auto time = std::localtime(&endianAdjustedTime); + if (time == nullptr) { + value = "Invalid"; + } else { + value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", *time); + } } catch (fmt::format_error &) { value = "Invalid"; } @@ -657,7 +667,12 @@ namespace hex::plugin::builtin { std::string value; try { - value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", *std::localtime(&endianAdjustedTime)); + auto time = std::localtime(&endianAdjustedTime); + if (time == nullptr) { + value = "Invalid"; + } else { + value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", *time); + } } catch (fmt::format_error &e) { value = "Invalid"; }