mirror of
https://github.com/meshtastic/firmware.git
synced 2026-10-10 23:56:25 -04:00
fix(mesh): use valid default packet history size (#11786)
This commit is contained in:
1 parent
42d32fcea6
commit
29a65aa13d
3 files changed
+37
-6
No files matched your search
@@ -17,14 +17,16 @@
|
||||
PacketHistory::PacketHistory(uint32_t size) : recentPacketsCapacity(0) // Initialize members
|
||||
{
|
||||
if (size < 4 || size > PACKETHISTORY_MAX) { // Copilot suggested - makes sense
|
||||
LOG_WARN("Packet History - Invalid size %d, using default %d", size, PACKETHISTORY_MAX);
|
||||
LOG_WARN("Packet History - Invalid size %u, using default %u", static_cast<unsigned>(size),
|
||||
static_cast<unsigned>(PACKETHISTORY_MAX));
|
||||
size = PACKETHISTORY_MAX; // Use default size if invalid
|
||||
}
|
||||
|
||||
#if !MESHTASTIC_EXCLUDE_PKT_HISTORY_HASH
|
||||
// Ensure capacity fits in uint16_t hash index (HASH_EMPTY = 0xFFFF is the sentinel)
|
||||
if (size >= HASH_EMPTY) {
|
||||
LOG_WARN("Packet History - Clamping size %d to %d (hash index limit)", size, HASH_EMPTY - 1);
|
||||
LOG_WARN("Packet History - Clamping size %u to %u (hash index limit)", static_cast<unsigned>(size),
|
||||
static_cast<unsigned>(HASH_EMPTY - 1));
|
||||
size = HASH_EMPTY - 1;
|
||||
}
|
||||
#endif
|
||||
@@ -33,7 +35,7 @@ PacketHistory::PacketHistory(uint32_t size) : recentPacketsCapacity(0) // Initia
|
||||
recentPacketsCapacity = size;
|
||||
recentPackets.reset(new PacketRecord[recentPacketsCapacity]);
|
||||
if (!recentPackets) { // No logging here, console/log probably uninitialized yet.
|
||||
LOG_ERROR("Packet History - Memory allocation failed for size=%d entries / %d Bytes", size,
|
||||
LOG_ERROR("Packet History - Memory allocation failed for size=%u entries / %zu Bytes", static_cast<unsigned>(size),
|
||||
sizeof(PacketRecord) * recentPacketsCapacity);
|
||||
recentPacketsCapacity = 0; // mark allocation fail
|
||||
return; // return early
|
||||
@@ -49,7 +51,7 @@ PacketHistory::PacketHistory(uint32_t size) : recentPacketsCapacity(0) // Initia
|
||||
hashMask = hashCapacity - 1;
|
||||
hashIndex.reset(new uint16_t[hashCapacity]);
|
||||
if (!hashIndex) {
|
||||
LOG_ERROR("Packet History - Hash index allocation failed for %d entries", hashCapacity);
|
||||
LOG_ERROR("Packet History - Hash index allocation failed for %u entries", static_cast<unsigned>(hashCapacity));
|
||||
hashCapacity = 0;
|
||||
hashMask = 0;
|
||||
return;
|
||||
@@ -601,4 +603,4 @@ inline uint8_t PacketHistory::getOurTxHopLimit(const PacketRecord &r)
|
||||
inline void PacketHistory::setOurTxHopLimit(PacketRecord &r, uint8_t hopLimit)
|
||||
{
|
||||
r.hop_limit = (r.hop_limit & ~HOP_LIMIT_OUR_TX_MASK) | ((hopLimit << HOP_LIMIT_OUR_TX_SHIFT) & HOP_LIMIT_OUR_TX_MASK);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user