diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index 50b41488b2..1949e4859c 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -1296,6 +1296,16 @@ int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_si px4_clock_gettime(CLOCK_REALTIME, &ts); timestamp_utc = ts.tv_sec + (ts.tv_nsec / 1e9); + // Apply UTC offset parameter and handle potential underflow + int32_t utc_offset_seconds = _param_sdlog_utc_offset.get() * 60; + + if (utc_offset_seconds < 0 && timestamp_utc < (uint32_t)abs(utc_offset_seconds)) { + timestamp_utc = 0; + + } else { + timestamp_utc += utc_offset_seconds; + } + const char *replay_suffix = ""; if (_replay_file_name) { @@ -1315,7 +1325,6 @@ int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_si // Check if time is non-zero for valid UTC timestamp if (timestamp_utc > 0) { - timestamp_utc += _param_sdlog_utc_offset.get() * 60; tm tt = {}; gmtime_r(×tamp_utc, &tt);