[dpdk-dev] bus/fpga: use strlcpy instead of strncpy

Message ID 20180512070217.16735-1-pablo.de.lara.guarch@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

De Lara Guarch, Pablo May 12, 2018, 7:02 a.m. UTC
  Gcc 8 reports a build error:

drivers/bus/ifpga/ifpga_bus.c:161:2: error: ‘strncpy’ specified
bound 256 equals destination size [-Werror=stringop-truncation]
  strncpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 05fa3d4a6539 ("bus/ifpga: add Intel FPGA bus library")

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 drivers/bus/ifpga/ifpga_bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Thomas Monjalon May 13, 2018, 10:07 a.m. UTC | #1
12/05/2018 09:02, Pablo de Lara:
> Gcc 8 reports a build error:
> 
> drivers/bus/ifpga/ifpga_bus.c:161:2: error: ‘strncpy’ specified
> bound 256 equals destination size [-Werror=stringop-truncation]
>   strncpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Fixes: 05fa3d4a6539 ("bus/ifpga: add Intel FPGA bus library")
> 
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Applied, thanks
  
Xu, Rosen May 14, 2018, 10:06 a.m. UTC | #2
Hi,

> -----Original Message-----

> From: Thomas Monjalon [mailto:thomas@monjalon.net]

> Sent: Sunday, May 13, 2018 18:07

> To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>

> Cc: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>

> Subject: Re: [dpdk-dev] [PATCH] bus/fpga: use strlcpy instead of strncpy

> 

> 12/05/2018 09:02, Pablo de Lara:

> > Gcc 8 reports a build error:

> >

> > drivers/bus/ifpga/ifpga_bus.c:161:2: error: ‘strncpy’ specified bound

> > 256 equals destination size [-Werror=stringop-truncation]

> >   strncpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));

> >

> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> >

> > Fixes: 05fa3d4a6539 ("bus/ifpga: add Intel FPGA bus library")

> >

> > Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

> 

> Applied, thanks

Thanks a lot Pablo.
>
  

Patch

diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 16b7e06b6..45597a1bb 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -20,10 +20,10 @@ 
 #include <rte_memzone.h>
 #include <rte_eal.h>
 #include <rte_common.h>
-
 #include <rte_devargs.h>
 #include <rte_kvargs.h>
 #include <rte_alarm.h>
+#include <rte_string_fns.h>
 
 #include "rte_rawdev.h"
 #include "rte_rawdev_pmd.h"
@@ -158,7 +158,7 @@  ifpga_scan_one(struct rte_rawdev *rawdev,
 		rawdev->dev_ops->dev_start(rawdev))
 		goto free_dev;
 
-	strncpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
+	strlcpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
 	if (rawdev->dev_ops->firmware_load &&
 		rawdev->dev_ops->firmware_load(rawdev,
 				&afu_pr_conf)){