examples/vdpa: replace strncpy with strscpy function

Message ID 20181003193439.108373-1-xiaolong.ye@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series examples/vdpa: replace strncpy with strscpy function |

Checks

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

Commit Message

Xiaolong Ye Oct. 3, 2018, 7:34 p.m. UTC
  rte_strscpy is safer to use.

Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
---
 examples/vdpa/main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Maxime Coquelin Oct. 3, 2018, 1:31 p.m. UTC | #1
On 10/03/2018 09:34 PM, Xiaolong Ye wrote:
> rte_strscpy is safer to use.
> 
> Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
> ---
>   examples/vdpa/main.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

I'll squash it into initial commit.

Thanks,
Maxime
  
Maxime Coquelin Oct. 3, 2018, 2:13 p.m. UTC | #2
On 10/03/2018 10:28 PM, Ye Xiaolong wrote:
> On 10/03, Maxime Coquelin wrote:
>>
>>
>> On 10/03/2018 09:34 PM, Xiaolong Ye wrote:
>>> rte_strscpy is safer to use.
>>>
>>> Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
>>> ---
>>>    examples/vdpa/main.c | 5 +++--
>>>    1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>
>> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>>
>> I'll squash it into initial commit.

Squashed and pushed to dpdk-next-virtio.

Maxime
  
Xiaolong Ye Oct. 3, 2018, 8:28 p.m. UTC | #3
On 10/03, Maxime Coquelin wrote:
>
>
>On 10/03/2018 09:34 PM, Xiaolong Ye wrote:
>> rte_strscpy is safer to use.
>> 
>> Signed-off-by: Xiaolong Ye <xiaolong.ye@intel.com>
>> ---
>>   examples/vdpa/main.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>> 
>
>Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>
>I'll squash it into initial commit.

Thanks.

Xiaolong
>
>Thanks,
>Maxime
  

Patch

diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c
index f96fa88b7..c5e8f58ec 100644
--- a/examples/vdpa/main.c
+++ b/examples/vdpa/main.c
@@ -13,6 +13,7 @@ 
 #include <rte_vhost.h>
 #include <rte_vdpa.h>
 #include <rte_pci.h>
+#include <rte_string_fns.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_socket.h>
@@ -73,7 +74,7 @@  parse_args(int argc, char **argv)
 		case 0:
 			if (strncmp(long_option[idx].name, "iface",
 						MAX_PATH_LEN) == 0) {
-				strncpy(iface, optarg, MAX_PATH_LEN);
+				rte_strscpy(iface, optarg, MAX_PATH_LEN);
 				printf("iface %s\n", iface);
 			}
 			if (!strcmp(long_option[idx].name, "interactive")) {
@@ -325,7 +326,7 @@  static void cmd_create_vdpa_port_parsed(void *parsed_result,
 	struct cmd_create_result *res = parsed_result;
 	struct rte_vdpa_dev_addr addr;
 
-	strncpy(vports[devcnt].ifname, res->socket_path, MAX_PATH_LEN);
+	rte_strscpy(vports[devcnt].ifname, res->socket_path, MAX_PATH_LEN);
 	if (rte_pci_addr_parse(res->bdf, &addr.pci_addr) != 0) {
 		cmdline_printf(cl, "Unable to parse the given bdf.\n");
 		return;