Skip to content

Commit

Permalink
Fix size calculation of route/SNR array
Browse files Browse the repository at this point in the history
  • Loading branch information
GUVWAF committed Sep 9, 2024
1 parent 68d6ff8 commit 2f9dcee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/modules/TraceRouteModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ void TraceRouteModule::insertUnknownHops(meshtastic_MeshPacket &p, meshtastic_Ro
uint8_t hopsTaken = p.hop_start - p.hop_limit;
int8_t diff = hopsTaken - *route_count;
for (uint8_t i = 0; i < diff; i++) {
if (*route_count < sizeof(*route) / sizeof(route[0])) {
if (*route_count < ROUTE_SIZE) {
route[*route_count] = NODENUM_BROADCAST; // This will represent an unknown hop
*route_count += 1;
}
}
// Add unknown SNR values if necessary
diff = *route_count - *snr_count;
for (uint8_t i = 0; i < diff; i++) {
if (*snr_count < sizeof(*snr_list) / sizeof(snr_list[0])) {
if (*snr_count < ROUTE_SIZE) {
snr_list[*snr_count] = INT8_MIN; // This will represent an unknown SNR
*snr_count += 1;
}
Expand Down Expand Up @@ -89,15 +89,15 @@ void TraceRouteModule::appendMyIDandSNR(meshtastic_RouteDiscovery *updated, floa
snr_list = updated->snr_back;
}

if (*snr_count < sizeof(*snr_list) / sizeof(snr_list[0])) {
if (*snr_count < ROUTE_SIZE) {
snr_list[*snr_count] = (int8_t)(snr * 4); // Convert SNR to 1 byte
*snr_count += 1;
}
if (SNRonly)
return;

// Length of route array can normally not be exceeded due to the max. hop_limit of 7
if (*route_count < sizeof(*route) / sizeof(route[0])) {
if (*route_count < ROUTE_SIZE) {
route[*route_count] = myNodeInfo.my_node_num;
*route_count += 1;
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/modules/TraceRouteModule.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "ProtobufModule.h"

#define ROUTE_SIZE sizeof(((meshtastic_RouteDiscovery *)0)->route) / sizeof(((meshtastic_RouteDiscovery *)0)->route[0])

/**
* A module that traces the route to a certain destination node
*/
Expand Down

0 comments on commit 2f9dcee

Please sign in to comment.