Skip to content

Commit 9678b0b

Browse files
author
realtag
committed
Fix repeater ping path formatting for multi-byte hashes
1 parent 74cb3d0 commit 9678b0b

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

examples/simple_repeater/MyMesh.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,37 @@ static void formatPathString(const uint8_t* path, uint8_t path_len, char* dest,
176176
return;
177177
}
178178

179+
if (!mesh::Packet::isValidPathLen(path_len)) {
180+
strncpy(dest, "invalid", dest_len);
181+
dest[dest_len - 1] = 0;
182+
return;
183+
}
184+
185+
uint8_t hash_count = path_len & 63;
186+
uint8_t hash_size = (path_len >> 6) + 1;
187+
if (hash_count == 0) {
188+
strncpy(dest, "direct", dest_len);
189+
dest[dest_len - 1] = 0;
190+
return;
191+
}
179192
size_t used = 0;
180-
for (uint8_t i = 0; i < path_len; i++) {
193+
for (uint8_t i = 0; i < hash_count; i++) {
181194
const char* sep = (i == 0) ? "" : ">";
182-
int written = snprintf(dest + used, dest_len - used, "%s%02X", sep, path[i]);
195+
int written = snprintf(dest + used, dest_len - used, "%s", sep);
183196
if (written < 0 || (size_t)written >= dest_len - used) {
184197
dest[dest_len - 1] = 0;
185198
return;
186199
}
187200
used += (size_t)written;
201+
202+
for (uint8_t j = 0; j < hash_size; j++) {
203+
written = snprintf(dest + used, dest_len - used, "%02X", path[i * hash_size + j]);
204+
if (written < 0 || (size_t)written >= dest_len - used) {
205+
dest[dest_len - 1] = 0;
206+
return;
207+
}
208+
used += (size_t)written;
209+
}
188210
}
189211
}
190212

0 commit comments

Comments
 (0)