app/flow-perf: fix logic to add comma every three digits

Message ID 08953a79d2cf9a91cc687a25b964c52cf6bb3e09.1654898425.git.rahul.lakkireddy@chelsio.com (mailing list archive)
State Rejected, archived
Delegated to: David Marchand
Headers
Series app/flow-perf: fix logic to add comma every three digits |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Rahul Lakkireddy June 10, 2022, 10:06 p.m. UTC
  Add comma after 1 in 1000 too, like 1,000. Also, since max uint64_t is
a 20 digit number, increase space in temporary array to hold 20 digits.
Fixes following warnings when using optimization=1 build flag with
GCC 11.

../app/test-flow-perf/main.c: In function ‘pretty_number’:
../app/test-flow-perf/main.c:1737:28: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
         sprintf(p[i++], "%d", (int)n);
                            ^
../app/test-flow-perf/main.c:1737:9: note: ‘sprintf’ output between 2 and 5 bytes into a destination of size 4
         sprintf(p[i++], "%d", (int)n);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Bugzilla ID: 1029
Fixes: 15c431864000 ("app/flow-perf: add packet forwarding support")
Cc: stable@dpdk.org

Reported-by: Daxue Gao <daxuex.gao@intel.com>
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
---
 app/test-flow-perf/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger June 10, 2022, 11:45 p.m. UTC | #1
On Sat, 11 Jun 2022 03:36:43 +0530
Rahul Lakkireddy <rahul.lakkireddy@chelsio.com> wrote:

> Add comma after 1 in 1000 too, like 1,000. Also, since max uint64_t is
> a 20 digit number, increase space in temporary array to hold 20 digits.
> Fixes following warnings when using optimization=1 build flag with
> GCC 11.
> 
> ../app/test-flow-perf/main.c: In function ‘pretty_number’:
> ../app/test-flow-perf/main.c:1737:28: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
>          sprintf(p[i++], "%d", (int)n);
>                             ^
> ../app/test-flow-perf/main.c:1737:9: note: ‘sprintf’ output between 2 and 5 bytes into a destination of size 4
>          sprintf(p[i++], "%d", (int)n);
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Bugzilla ID: 1029
> Fixes: 15c431864000 ("app/flow-perf: add packet forwarding support")
> Cc: stable@dpdk.org
> 
> Reported-by: Daxue Gao <daxuex.gao@intel.com>
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>

There was a better alternative proposed here:

https://patchwork.dpdk.org/project/dpdk/patch/20220518101657.1230416-12-david.marchand@redhat.com/
  
Rahul Lakkireddy June 13, 2022, 9:55 a.m. UTC | #2
On Friday, June 06/10/22, 2022 at 16:45:22 -0700, Stephen Hemminger wrote:
> On Sat, 11 Jun 2022 03:36:43 +0530
> Rahul Lakkireddy <rahul.lakkireddy@chelsio.com> wrote:
> 
> > Add comma after 1 in 1000 too, like 1,000. Also, since max uint64_t is
> > a 20 digit number, increase space in temporary array to hold 20 digits.
> > Fixes following warnings when using optimization=1 build flag with
> > GCC 11.
> > 
> > ../app/test-flow-perf/main.c: In function ‘pretty_number’:
> > ../app/test-flow-perf/main.c:1737:28: warning: ‘sprintf’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
> >          sprintf(p[i++], "%d", (int)n);
> >                             ^
> > ../app/test-flow-perf/main.c:1737:9: note: ‘sprintf’ output between 2 and 5 bytes into a destination of size 4
> >          sprintf(p[i++], "%d", (int)n);
> >          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 
> > Bugzilla ID: 1029
> > Fixes: 15c431864000 ("app/flow-perf: add packet forwarding support")
> > Cc: stable@dpdk.org
> > 
> > Reported-by: Daxue Gao <daxuex.gao@intel.com>
> > Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> 
> There was a better alternative proposed here:
> 
> https://patchwork.dpdk.org/project/dpdk/patch/20220518101657.1230416-12-david.marchand@redhat.com/

Thanks Stephen. I missed this earlier patch from David. My patch
can be dropped.

Thanks,
Rahul
  

Patch

diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 56d43734e3..594507a85e 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -1724,11 +1724,11 @@  do_tx(struct lcore_info *li, uint16_t cnt, uint16_t tx_port,
 static char *
 pretty_number(uint64_t n, char *buf)
 {
-	char p[6][4];
+	char p[7][4];
 	int i = 0;
 	int off = 0;
 
-	while (n > 1000) {
+	while (n >= 1000) {
 		sprintf(p[i], "%03d", (int)(n % 1000));
 		n /= 1000;
 		i += 1;