mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 13:27:34 +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:
@@ -194,7 +194,7 @@ CM8JL65::CM8JL65(const char *port, uint8_t rotation) :
|
||||
_comms_errors(perf_alloc(PC_COUNT, "cm8jl65_com_err"))
|
||||
{
|
||||
/* store port name */
|
||||
strncpy(_port, port, sizeof(_port));
|
||||
strncpy(_port, port, sizeof(_port) - 1);
|
||||
/* enforce null termination */
|
||||
_port[sizeof(_port) - 1] = '\0';
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ extern "C" __EXPORT int pga460_main(int argc, char *argv[]);
|
||||
PGA460::PGA460(const char *port)
|
||||
{
|
||||
// Store port name.
|
||||
strncpy(_port, port, sizeof(_port));
|
||||
strncpy(_port, port, sizeof(_port) - 1);
|
||||
// Enforce null termination.
|
||||
_port[sizeof(_port) - 1] = '\0';
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ SF0X::SF0X(const char *port, uint8_t rotation) :
|
||||
_comms_errors(perf_alloc(PC_COUNT, "sf0x_com_err"))
|
||||
{
|
||||
/* store port name */
|
||||
strncpy(_port, port, sizeof(_port));
|
||||
strncpy(_port, port, sizeof(_port) - 1);
|
||||
/* enforce null termination */
|
||||
_port[sizeof(_port) - 1] = '\0';
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ TFMINI::TFMINI(const char *port, uint8_t rotation) :
|
||||
_comms_errors(perf_alloc(PC_COUNT, "tfmini_com_err"))
|
||||
{
|
||||
/* store port name */
|
||||
strncpy(_port, port, sizeof(_port));
|
||||
strncpy(_port, port, sizeof(_port) - 1);
|
||||
/* enforce null termination */
|
||||
_port[sizeof(_port) - 1] = '\0';
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ Radar::Radar(uint8_t rotation, const char *port) :
|
||||
|
||||
{
|
||||
/* store port name */
|
||||
strncpy(_port, port, sizeof(_port));
|
||||
strncpy(_port, port, sizeof(_port) - 1);
|
||||
/* enforce null termination */
|
||||
_port[sizeof(_port) - 1] = '\0';
|
||||
}
|
||||
|
||||
@@ -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