[core] Fix ESPTime crash (#11705)

This commit is contained in:
Jonathan Swoboda
2025-11-03 21:09:34 -05:00
committed by GitHub
parent 6220084fe6
commit 326975ccad

View File

@@ -84,6 +84,9 @@ struct ESPTime {
*/
static ESPTime from_epoch_local(time_t epoch) {
struct tm *c_tm = ::localtime(&epoch);
if (c_tm == nullptr) {
return ESPTime{}; // Return an invalid ESPTime
}
return ESPTime::from_c_tm(c_tm, epoch);
}
/** Convert an UTC epoch timestamp to a UTC time ESPTime instance.
@@ -93,6 +96,9 @@ struct ESPTime {
*/
static ESPTime from_epoch_utc(time_t epoch) {
struct tm *c_tm = ::gmtime(&epoch);
if (c_tm == nullptr) {
return ESPTime{}; // Return an invalid ESPTime
}
return ESPTime::from_c_tm(c_tm, epoch);
}