Skip to content

Commit 96e786f

Browse files
author
Scott Powell
committed
* FIX: for divide by zero crash
1 parent 3d9378d commit 96e786f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
397397

398398
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
399399
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
400-
return getRNG()->nextInt(0, 5*t);
400+
return getRNG()->nextInt(0, 5*t + 1);
401401
}
402402
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
403403
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
404-
return getRNG()->nextInt(0, 5*t);
404+
return getRNG()->nextInt(0, 5*t + 1);
405405
}
406406

407407
void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender,

examples/simple_room_server/MyMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ const char *MyMesh::getLogDateTime() {
262262

263263
uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) {
264264
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.tx_delay_factor);
265-
return getRNG()->nextInt(0, 5*t);
265+
return getRNG()->nextInt(0, 5*t + 1);
266266
}
267267
uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
268268
uint32_t t = (_radio->getEstAirtimeFor(packet->path_len + packet->payload_len + 2) * _prefs.direct_tx_delay_factor);
269-
return getRNG()->nextInt(0, 5*t);
269+
return getRNG()->nextInt(0, 5*t + 1);
270270
}
271271

272272
bool MyMesh::allowPacketForward(const mesh::Packet *packet) {

0 commit comments

Comments
 (0)