You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native builds: host min/max/constrain return a dangling reference, so the companion stores a hop limit of 0 #810
On a native companion (v1.18.0, built from source with meshcore-native main 9097ca8 and MeshBench v0.4.1), setting the auto-add hop limit stores 0, whatever value is sent. CMD_SET_AUTOADD_CONFIG 3a 0e 07, then CMD_GET_AUTOADD_CONFIG, reads back 19 0e 00. On a radio it reads 19 0e 07.
The cause is the host's min, max and constrain in variants/host/HostArduino.h:62-73. They're declared -> decltype(a < b ? a : b), and when both arguments have one type that is a reference to the function's by-value parameter, which is gone once it returns. Optimised, min(cmd_frame[2], (uint8_t)64) (MyMesh.cpp:2026) reads a stale stack slot.
It's undefined behaviour at every one-type call. In MeshCore v1.18.0, across the companion, repeater and room server, there are 10 such calls, including:
constrain of the radio's frequency and bandwidth (MyMesh.cpp:989-990, CommonCLI.cpp:112-113);
the packet score's max(0.0, min(1.0, …)) (RadioLibWrappers.cpp:241).
Those happened to return the right values in my builds, but nothing guarantees it.
How to reproduce it
Run a native companion and connect a client.
Send 3a 0e 07 (CMD_SET_AUTOADD_CONFIG with a hop limit of 7), then 3b (CMD_GET_AUTOADD_CONFIG).
The reply is 19 0e 00: the hop limit is 0.
Alone, without the firmware:
#include<cstdint>template <classT, classU>
constexprautomin(T a, U b) -> decltype(a < b ? a : b) { return a < b ? a : b; }
volatileuint8_t x = 7;
intmain() { returnmin(x, (uint8_t)64); } // exits 7 at -O0, 0 at -O2 (g++ 14.2)
Version
meshcore-native main 9097ca8 (and every tag I looked at), MeshBench v0.4.1, MeshCore companion-v1.18.0, g++ from Debian trixie.
Platform
Linux
Anything else
Fix, with a test that fails without it: MeshBench/meshcore-native#37. It returns std::decay_t of the same expression. The one-type call sites, and how I found them, are listed there.
Activity
A13xB0 commentedon Nov 21, 2026
Fixed by MeshBench/meshcore-native#37. Thanks for the detailed report and the fix.