From b64eda234f2f6dd37dc19ad00e235eb1061368df Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Thu, 4 Jun 2026 13:49:22 +0200 Subject: [PATCH] fix(nav): reject non-numeric lat/lon in Add-by-coords MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The form's keyboard is the full alphanumeric one, and atof() silently read a non-numeric entry as 0.0 — so typing letters created a waypoint at (0, 0). Validate each coordinate with strtod and require the whole field to be numeric; bad input now reports "Lat/Lon invalid" and saves nothing. Co-Authored-By: Claude Opus 4.8 --- examples/companion_radio/ui-new/TrailScreen.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/companion_radio/ui-new/TrailScreen.h b/examples/companion_radio/ui-new/TrailScreen.h index 741f74c0..34109ec2 100644 --- a/examples/companion_radio/ui-new/TrailScreen.h +++ b/examples/companion_radio/ui-new/TrailScreen.h @@ -440,10 +440,23 @@ private: dst[cap - 1] = '\0'; } + // Parse a numeric field: true only when the whole string is a number (so a + // stray letter from the full keyboard can't silently read as 0). + static bool parseNum(const char* s, double& out) { + if (!s || !s[0]) return false; + char* end = nullptr; + out = strtod(s, &end); + if (end == s) return false; // nothing numeric parsed + while (*end == ' ') end++; + return *end == '\0'; // no trailing non-numeric chars + } + // Validate the form and save the waypoint. void commitAddForm() { - if (!_add_lat[0] || !_add_lon[0]) { _task->showAlert("Lat/Lon needed", 1200); return; } - double la = atof(_add_lat), lo = atof(_add_lon); + double la, lo; + if (!parseNum(_add_lat, la) || !parseNum(_add_lon, lo)) { + _task->showAlert("Lat/Lon invalid", 1200); return; + } if (_add_lat_neg) la = -la; if (_add_lon_neg) lo = -lo; if (la < -90.0 || la > 90.0 || lo < -180.0 || lo > 180.0) {