summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/edi/common.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/edi/common.cpp b/lib/edi/common.cpp
index e4a51b4..470b3ba 100644
--- a/lib/edi/common.cpp
+++ b/lib/edi/common.cpp
@@ -103,7 +103,10 @@ std::chrono::system_clock::time_point frame_timestamp_t::to_system_clock() const
auto ts = chrono::system_clock::from_time_t(to_unix_epoch());
// PPS offset in seconds = tsta / 16384000
- ts += chrono::nanoseconds(std::lrint(tsta / 0.016384));
+ // We cannot use nanosecond resolution because not all platforms use a
+ // system_clock that has nanosecond precision. It's not really important,
+ // as this function is only used for debugging.
+ ts += chrono::microseconds(std::lrint(tsta / 16.384));
return ts;
}
@@ -239,7 +242,9 @@ decode_state_t TagDispatcher::decode_afpacket(
return {false, 0};
}
- if (m_last_seq + (uint16_t)1 != seq) {
+ // SEQ wraps at 0xFFFF, unsigned integer overflow is intentional
+ const uint16_t expected_seq = m_last_seq + 1;
+ if (expected_seq != seq) {
etiLog.level(warn) << "EDI AF Packet sequence error, " << seq;
}
m_last_seq = seq;
@@ -307,15 +312,17 @@ bool TagDispatcher::decode_tagpacket(const vector<uint8_t> &payload)
uint32_t taglength = read_32b(payload.begin() + i + 4);
if (taglength % 8 != 0) {
- etiLog.log(warn, "Invalid tag length: not multiple of 8!");
+ etiLog.log(warn, "Invalid EDI tag length, not multiple of 8!");
break;
}
taglength /= 8;
length = taglength;
- if (i + 8 + taglength >= payload.size()) {
- etiLog.log(warn, "Invalid tag length: tag larger than tagpacket!");
+ const size_t calculated_length = i + 8 + taglength;
+ if (calculated_length > payload.size()) {
+ etiLog.log(warn, "Invalid EDI tag length: tag larger %zu than tagpacket %zu!",
+ calculated_length, payload.size());
break;
}