[dpdk-dev,v6,16/16] app/test-bbdev: strcpy ok for allocated string

Message ID 152627407240.52758.12345283817005640967.stgit@localhost.localdomain (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

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

Commit Message

Andy Green May 14, 2018, 5:01 a.m. UTC
  Signed-off-by: Andy Green <andy@warmcat.com>
Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
Cc: stable@dpdk.org
---
 app/test-bbdev/test_bbdev_vector.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Ferruh Yigit May 14, 2018, 9:03 p.m. UTC | #1
On 5/14/2018 6:01 AM, Andy Green wrote:

.../app/test-bbdev/test_bbdev_vector.c:917:5:
   error: ‘strncat’ output truncated before terminating nul copying as many
bytes from a string as its length [-Werror=stringop-truncation]
     strncat(entry, line, strlen(line));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> Fixes: f714a18885a6 ("app/testbbdev: add test application for bbdev")
> Cc: stable@dpdk.org

> Signed-off-by: Andy Green <andy@warmcat.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

> ---
>  app/test-bbdev/test_bbdev_vector.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
> index c574f2135..81b8ee78f 100644
> --- a/app/test-bbdev/test_bbdev_vector.c
> +++ b/app/test-bbdev/test_bbdev_vector.c
> @@ -891,7 +891,6 @@ test_bbdev_vector_read(const char *filename,
>  			goto exit;
>  		}
>  
> -		memset(entry, 0, strlen(line) + 1);

This one seems belong to 15/16, will move there.

>  		strcpy(entry, line);
>  
>  		/* check if entry ends with , or = */
> @@ -914,7 +913,8 @@ test_bbdev_vector_read(const char *filename,
>  				}
>  
>  				entry = entry_extended;
> -				strncat(entry, line, strlen(line));
> +				/* entry has been allocated accordingly */
> +				strcpy(&entry[strlen(entry)], line);
>  
>  				if (entry[strlen(entry) - 1] != ',')
>  					break;
>
  

Patch

diff --git a/app/test-bbdev/test_bbdev_vector.c b/app/test-bbdev/test_bbdev_vector.c
index c574f2135..81b8ee78f 100644
--- a/app/test-bbdev/test_bbdev_vector.c
+++ b/app/test-bbdev/test_bbdev_vector.c
@@ -891,7 +891,6 @@  test_bbdev_vector_read(const char *filename,
 			goto exit;
 		}
 
-		memset(entry, 0, strlen(line) + 1);
 		strcpy(entry, line);
 
 		/* check if entry ends with , or = */
@@ -914,7 +913,8 @@  test_bbdev_vector_read(const char *filename,
 				}
 
 				entry = entry_extended;
-				strncat(entry, line, strlen(line));
+				/* entry has been allocated accordingly */
+				strcpy(&entry[strlen(entry)], line);
 
 				if (entry[strlen(entry) - 1] != ',')
 					break;