Skip to content

Commit 94a33b2

Browse files
Merge pull request #4518 from ZoneMinder/copilot/fix-time-t-format-specifier
Fix time_t format specifiers for ILP32 platforms with 64-bit time_t
2 parents 598a438 + 2c2047c commit 94a33b2

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

_codeql_detected_source_root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.

src/zm_event.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ Event::~Event() {
201201
}
202202

203203
std::string sql = stringtf(
204-
"UPDATE Events SET Name='%s%" PRIu64 "', EndDateTime = from_unixtime(%ld), Length = %.2f, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d, MaxScoreFrameId=%d, DefaultVideo='%s', DiskSpace=%" PRIu64 " WHERE Id = %" PRIu64 " AND Name='New Event'",
205-
monitor->Substitute(monitor->EventPrefix(), start_time).c_str(), id, std::chrono::system_clock::to_time_t(end_time),
204+
"UPDATE Events SET Name='%s%" PRIu64 "', EndDateTime = from_unixtime(%jd), Length = %.2f, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d, MaxScoreFrameId=%d, DefaultVideo='%s', DiskSpace=%" PRIu64 " WHERE Id = %" PRIu64 " AND Name='New Event'",
205+
monitor->Substitute(monitor->EventPrefix(), start_time).c_str(), id, static_cast<intmax_t>(std::chrono::system_clock::to_time_t(end_time)),
206206
delta_time.count(),
207207
frames, alarm_frames,
208208
tot_score, static_cast<uint32>(alarm_frames ? (tot_score / alarm_frames) : 0), max_score, max_score_frame_id,
@@ -213,8 +213,8 @@ Event::~Event() {
213213
if (!zmDbDoUpdate(sql)) {
214214
// Name might have been changed during recording, so just do the update without changing the name.
215215
sql = stringtf(
216-
"UPDATE Events SET EndDateTime = from_unixtime(%ld), Length = %.2f, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d, MaxScoreFrameId=%d, DefaultVideo='%s', DiskSpace=%" PRIu64 " WHERE Id = %" PRIu64,
217-
std::chrono::system_clock::to_time_t(end_time),
216+
"UPDATE Events SET EndDateTime = from_unixtime(%jd), Length = %.2f, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d, MaxScoreFrameId=%d, DefaultVideo='%s', DiskSpace=%" PRIu64 " WHERE Id = %" PRIu64,
217+
static_cast<intmax_t>(std::chrono::system_clock::to_time_t(end_time)),
218218
delta_time.count(),
219219
frames, alarm_frames,
220220
tot_score, static_cast<uint32>(alarm_frames ? (tot_score / alarm_frames) : 0), max_score, max_score_frame_id,
@@ -392,10 +392,10 @@ void Event::WriteDbFrames() {
392392
while (frame_data.size()) {
393393
Frame *frame = frame_data.front();
394394
frame_data.pop();
395-
frame_insert_sql += stringtf("\n( %" PRIu64 ", %d, '%s', from_unixtime( %ld ), %.2f, %d ),",
395+
frame_insert_sql += stringtf("\n( %" PRIu64 ", %d, '%s', from_unixtime( %jd ), %.2f, %d ),",
396396
id, frame->frame_id,
397397
frame_type_names[frame->type],
398-
std::chrono::system_clock::to_time_t(frame->timestamp),
398+
static_cast<intmax_t>(std::chrono::system_clock::to_time_t(frame->timestamp)),
399399
std::chrono::duration_cast<FPSeconds>(frame->delta).count(),
400400
frame->score);
401401
if (config.record_event_stats and frame->zone_stats.size()) {

src/zm_logger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,8 @@ void Logger::logPrint(bool hex, const char *filepath, int line, int level, const
531531
"INSERT INTO `Logs` "
532532
"( `TimeKey`, `Component`, `ServerId`, `Pid`, `Level`, `Code`, `Message`, `File`, `Line` )"
533533
" VALUES "
534-
"( %ld.%06" PRIi64 ", '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
535-
now_sec, static_cast<int64>(now_frac.count()), mId.c_str(), staticConfig.SERVER_ID, tid, level, classString,
534+
"( %jd.%06" PRIi64 ", '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
535+
static_cast<intmax_t>(now_sec), static_cast<int64>(now_frac.count()), mId.c_str(), staticConfig.SERVER_ID, tid, level, classString,
536536
escapedString.c_str(), file, line);
537537
dbQueue.push(std::move(sql_string));
538538
}

src/zm_rtp_source.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,17 @@ void RtpSource::updateRtcpData(
203203
timeval ntpTime = zm::chrono::duration_cast<timeval>(
204204
Seconds(ntpTimeSecs) + Microseconds((Microseconds::period::den * (ntpTimeFrac >> 16)) / (1 << 16)));
205205

206-
Debug(5, "ntpTime: %ld.%06ld, rtpTime: %x", ntpTime.tv_sec, ntpTime.tv_usec, rtpTime);
206+
Debug(5, "ntpTime: %jd.%06ld, rtpTime: %x", static_cast<intmax_t>(ntpTime.tv_sec), ntpTime.tv_usec, rtpTime);
207207

208208
if ( mBaseTimeNtp.tv_sec == 0 ) {
209209
mBaseTimeReal = std::chrono::system_clock::now();
210210
mBaseTimeNtp = ntpTime;
211211
mBaseTimeRtp = rtpTime;
212212
} else if ( !mRtpClock ) {
213-
Debug(5, "lastSrNtpTime: %ld.%06ld, rtpTime: %x"
214-
"ntpTime: %ld.%06ld, rtpTime: %x",
215-
mLastSrTimeNtp.tv_sec, mLastSrTimeNtp.tv_usec, rtpTime,
216-
ntpTime.tv_sec, ntpTime.tv_usec, rtpTime);
213+
Debug(5, "lastSrNtpTime: %jd.%06ld, rtpTime: %x"
214+
"ntpTime: %jd.%06ld, rtpTime: %x",
215+
static_cast<intmax_t>(mLastSrTimeNtp.tv_sec), mLastSrTimeNtp.tv_usec, rtpTime,
216+
static_cast<intmax_t>(ntpTime.tv_sec), ntpTime.tv_usec, rtpTime);
217217

218218
FPSeconds diffNtpTime =
219219
zm::chrono::duration_cast<Microseconds>(ntpTime) - zm::chrono::duration_cast<Microseconds>(mBaseTimeNtp);

src/zm_rtsp_server_device_source.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ void ZoneMinderDeviceSource::deliverFrame() {
107107
} else {
108108
fFrameSize = nal_size;
109109
}
110-
Debug(2, "deliverFrame stream: %d timestamp: %ld.%06ld size: %d queuesize: %d",
110+
Debug(2, "deliverFrame stream: %d timestamp: %jd.%06ld size: %d queuesize: %d",
111111
m_stream->index,
112-
frame->m_timestamp.tv_sec, frame->m_timestamp.tv_usec,
112+
static_cast<intmax_t>(frame->m_timestamp.tv_sec), frame->m_timestamp.tv_usec,
113113
fFrameSize,
114114
m_captureQueue.size()
115115
);

0 commit comments

Comments
 (0)