app: fix gcc 12 array bounds warning

Message ID 20220616103944.132686-1-wenxuanx.wu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series app: fix gcc 12 array bounds warning |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing warning apply patch failure
ci/Intel-compilation warning apply issues

Commit Message

Wu, WenxuanX June 16, 2022, 10:39 a.m. UTC
  From: Wenxuan Wu <wenxuanx.wu@intel.com>

when n == 1000, and it would overflow the array size of 4 bytes with
nul terminator. Change the logic to avoid this warning.

Fixes: 15c431864000 ("app/flow-perf: add packet forwarding support")
Cc: stable@dpdk.org
Signed-off-by: Wenxuan Wu <wenxuanx.wu@intel.com>
---
 app/test-flow-perf/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

David Marchand June 16, 2022, 1:16 p.m. UTC | #1
On Thu, Jun 16, 2022 at 12:40 PM <wenxuanx.wu@intel.com> wrote:
>
> From: Wenxuan Wu <wenxuanx.wu@intel.com>
>
> when n == 1000, and it would overflow the array size of 4 bytes with
> nul terminator. Change the logic to avoid this warning.
>
> Fixes: 15c431864000 ("app/flow-perf: add packet forwarding support")
> Cc: stable@dpdk.org
> Signed-off-by: Wenxuan Wu <wenxuanx.wu@intel.com>

A different fix is already merged.
Please check: https://git.dpdk.org/dpdk/commit/?id=5fc2eece8d45
  

Patch

diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 56d43734e3..661d562158 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -1728,7 +1728,7 @@  pretty_number(uint64_t n, char *buf)
 	int i = 0;
 	int off = 0;
 
-	while (n > 1000) {
+	while (n >= 1000) {
 		sprintf(p[i], "%03d", (int)(n % 1000));
 		n /= 1000;
 		i += 1;