mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 22:23:33 +08:00
drivers: fix -Wstringop-truncation
GCC 9 complained about stringop-truncation which is a cautionary message to prevent using strncpy with non-null terminated strings. We can fix this by copying one byte less than the destination size and then manually adding the null termination, as we already do.
This commit is contained in:
@@ -285,7 +285,7 @@ GPS::GPS(const char *path, gps_driver_mode_t mode, GPSHelper::Interface interfac
|
||||
_instance(instance)
|
||||
{
|
||||
/* store port name */
|
||||
strncpy(_port, path, sizeof(_port));
|
||||
strncpy(_port, path, sizeof(_port) - 1);
|
||||
/* enforce null termination */
|
||||
_port[sizeof(_port) - 1] = '\0';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user