mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
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:
parent
497704f3b9
commit
9849d90877
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user