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 <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche 2026-02-09 15:10:56 -08:00
parent 497704f3b9
commit 9849d90877

View File

@ -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;