From 9849d908770eb493c7e5c61336944cc2839253ea Mon Sep 17 00:00:00 2001 From: Ramon Roche Date: Mon, 9 Feb 2026 15:10:56 -0800 Subject: [PATCH] gps: add null check for path in GPS constructor Guard the strncpy call with a null check to prevent undefined behavior if the constructor is ever called with a null path pointer. Fixes clang-analyzer-core.NonNullParamChecker diagnostic. Signed-off-by: Ramon Roche --- src/drivers/gps/gps.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/drivers/gps/gps.cpp b/src/drivers/gps/gps.cpp index b33e27ac22..464eb892e9 100644 --- a/src/drivers/gps/gps.cpp +++ b/src/drivers/gps/gps.cpp @@ -318,9 +318,13 @@ GPS::GPS(const char *path, gps_driver_mode_t mode, GPSHelper::Interface interfac _instance(instance) { /* store port name */ - strncpy(_port, path, sizeof(_port) - 1); - /* enforce null termination */ - _port[sizeof(_port) - 1] = '\0'; + if (path != nullptr) { + strncpy(_port, path, sizeof(_port) - 1); + _port[sizeof(_port) - 1] = '\0'; + + } else { + _port[0] = '\0'; + } _sensor_gps.heading = NAN; _sensor_gps.heading_offset = NAN;