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:
Julian Oes 2019-05-14 14:23:53 +02:00 committed by Beat Küng
parent 3ab75b83ce
commit b20feacdb5
6 changed files with 6 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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