fix: Crash when selecting invalid time_t

This commit is contained in:
WerWolv
2025-05-09 19:33:01 +02:00
parent 8081dff6b6
commit e289380c39

View File

@@ -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";
}