From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, ferruh.yigit@xilinx.com, stable@dpdk.org,
Wisam Jaddo <wisamm@nvidia.com>
Subject: [PATCH 11/12] app/flow-perf: fix build with GCC 12
Date: Wed, 18 May 2022 12:16:56 +0200 [thread overview]
Message-ID: <20220518101657.1230416-12-david.marchand@redhat.com> (raw)
In-Reply-To: <20220518101657.1230416-1-david.marchand@redhat.com>
GCC 12 raises the following warning:
../app/test-flow-perf/main.c: In function ‘start_forwarding’:
../app/test-flow-perf/main.c:1737:28: error: ‘sprintf’ may write a
terminating nul past the end of the destination
[-Werror=format-overflow=]
1737 | sprintf(p[i++], "%d", (int)n);
| ^
In function ‘pretty_number’,
inlined from ‘packet_per_second_stats’ at
../app/test-flow-perf/main.c:1792:4,
inlined from ‘start_forwarding’ at
../app/test-flow-perf/main.c:1831:3:
[...]
We can simplify this code and rely on libc integer formatting via
this system locales.
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
app/test-flow-perf/main.c | 48 ++++++++-------------------------------
1 file changed, 9 insertions(+), 39 deletions(-)
diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c
index 56d43734e3..3922e92ded 100644
--- a/app/test-flow-perf/main.c
+++ b/app/test-flow-perf/main.c
@@ -16,6 +16,7 @@
* gives packet per second measurement.
*/
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1713,36 +1714,6 @@ do_tx(struct lcore_info *li, uint16_t cnt, uint16_t tx_port,
rte_pktmbuf_free(li->pkts[i]);
}
-/*
- * Method to convert numbers into pretty numbers that easy
- * to read. The design here is to add comma after each three
- * digits and set all of this inside buffer.
- *
- * For example if n = 1799321, the output will be
- * 1,799,321 after this method which is easier to read.
- */
-static char *
-pretty_number(uint64_t n, char *buf)
-{
- char p[6][4];
- int i = 0;
- int off = 0;
-
- while (n > 1000) {
- sprintf(p[i], "%03d", (int)(n % 1000));
- n /= 1000;
- i += 1;
- }
-
- sprintf(p[i++], "%d", (int)n);
-
- while (i--)
- off += sprintf(buf + off, "%s,", p[i]);
- buf[strlen(buf) - 1] = '\0';
-
- return buf;
-}
-
static void
packet_per_second_stats(void)
{
@@ -1764,7 +1735,6 @@ packet_per_second_stats(void)
uint64_t total_rx_pkts = 0;
uint64_t total_tx_drops = 0;
uint64_t tx_delta, rx_delta, drops_delta;
- char buf[3][32];
int nr_valid_core = 0;
sleep(1);
@@ -1789,10 +1759,8 @@ packet_per_second_stats(void)
tx_delta = li->tx_pkts - oli->tx_pkts;
rx_delta = li->rx_pkts - oli->rx_pkts;
drops_delta = li->tx_drops - oli->tx_drops;
- printf("%6d %16s %16s %16s\n", i,
- pretty_number(tx_delta, buf[0]),
- pretty_number(drops_delta, buf[1]),
- pretty_number(rx_delta, buf[2]));
+ printf("%6d %'16.3"PRId64" %'16.3"PRId64" %'16.3"PRId64"\n",
+ i, tx_delta, drops_delta, rx_delta);
total_tx_pkts += tx_delta;
total_rx_pkts += rx_delta;
@@ -1803,10 +1771,9 @@ packet_per_second_stats(void)
}
if (nr_valid_core > 1) {
- printf("%6s %16s %16s %16s\n", "total",
- pretty_number(total_tx_pkts, buf[0]),
- pretty_number(total_tx_drops, buf[1]),
- pretty_number(total_rx_pkts, buf[2]));
+ printf("%6s %'16.3"PRId64" %'16.3"PRId64" %'16.3"PRId64"\n",
+ "total", total_tx_pkts, total_tx_drops,
+ total_rx_pkts);
nr_lines += 1;
}
@@ -2139,6 +2106,9 @@ main(int argc, char **argv)
if (argc > 1)
args_parse(argc, argv);
+ /* For more fancy, localised integer formatting. */
+ setlocale(LC_NUMERIC, "");
+
init_port();
nb_lcores = rte_lcore_count();
--
2.36.1
next prev parent reply other threads:[~2022-05-18 10:18 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-18 10:16 [PATCH 00/12] Fix compilation with gcc 12 David Marchand
2022-05-18 10:16 ` [PATCH 01/12] common/cpt: fix build with GCC 12 David Marchand
2022-05-20 20:23 ` Stephen Hemminger
2022-06-10 13:11 ` David Marchand
2022-06-13 11:40 ` [EXT] " Ankur Dwivedi
2022-06-16 9:30 ` David Marchand
2022-06-16 11:59 ` Ankur Dwivedi
2022-05-18 10:16 ` [PATCH 02/12] crypto/cnxk: " David Marchand
2022-05-20 20:24 ` Stephen Hemminger
2022-05-18 10:16 ` [PATCH 03/12] crypto/ipsec_mb: " David Marchand
2022-06-02 9:50 ` Bruce Richardson
2022-06-10 13:07 ` David Marchand
2022-06-11 15:34 ` Stephen Hemminger
2022-05-18 10:16 ` [PATCH 04/12] net/ena: " David Marchand
2022-05-20 20:28 ` Stephen Hemminger
2022-05-21 9:49 ` Morten Brørup
2022-05-21 16:23 ` Stephen Hemminger
2022-05-22 20:30 ` Morten Brørup
2022-06-11 15:34 ` Stephen Hemminger
2022-05-18 10:16 ` [PATCH 05/12] net/enetfec: " David Marchand
2022-06-10 13:08 ` David Marchand
2022-06-13 5:22 ` Sachin Saxena (OSS)
2022-06-14 8:16 ` Sachin Saxena (OSS)
2022-06-11 15:35 ` Stephen Hemminger
2022-05-18 10:16 ` [PATCH 06/12] net/ice: " David Marchand
2022-06-11 15:36 ` Stephen Hemminger
2022-05-18 10:16 ` [PATCH 07/12] net/ice/base: " David Marchand
2022-05-18 10:16 ` [PATCH 08/12] net/qede/base: " David Marchand
2022-05-20 20:29 ` Stephen Hemminger
2022-06-21 23:17 ` Stephen Hemminger
2022-06-22 15:42 ` David Marchand
2022-05-18 10:16 ` [PATCH 09/12] vdpa/ifc: " David Marchand
2022-05-18 11:48 ` Wang, Xiao W
2022-06-11 15:36 ` Stephen Hemminger
2022-05-18 10:16 ` [PATCH 10/12] vhost/crypto: " David Marchand
2022-06-02 10:08 ` Bruce Richardson
2022-06-14 9:22 ` David Marchand
2022-06-14 9:25 ` Bruce Richardson
2022-06-16 9:27 ` David Marchand
2022-06-11 15:36 ` Stephen Hemminger
2022-06-16 9:32 ` [PATCH v2] " David Marchand
2022-06-16 14:53 ` David Marchand
2022-05-18 10:16 ` David Marchand [this message]
2022-06-02 10:21 ` [PATCH 11/12] app/flow-perf: " Bruce Richardson
2022-06-08 9:03 ` Wisam Monther
2022-06-08 12:20 ` David Marchand
2022-06-13 7:49 ` Wisam Monther
2022-06-11 15:37 ` Stephen Hemminger
2022-05-18 10:16 ` [PATCH 12/12] test/ipsec: " David Marchand
2022-06-02 18:41 ` Medvedkin, Vladimir
2022-06-03 7:45 ` David Marchand
2022-06-03 7:56 ` Bruce Richardson
2022-06-03 9:41 ` David Marchand
2022-06-03 15:57 ` Medvedkin, Vladimir
2022-06-11 15:38 ` Stephen Hemminger
2022-06-16 9:33 ` [PATCH v2] " David Marchand
2022-06-17 12:06 ` David Marchand
2022-06-20 9:07 ` [EXT] " Akhil Goyal
2022-06-20 15:06 ` Medvedkin, Vladimir
2022-06-16 14:46 ` [PATCH v3] vhost/crypto: " David Marchand
2022-06-17 13:59 ` Maxime Coquelin
2022-06-21 9:31 ` Maxime Coquelin
2022-06-22 9:01 ` Poczatek, Jakub
2022-06-22 9:26 ` Zhang, Roy Fan
2022-06-22 14:07 ` David Marchand
2022-06-22 15:21 ` Poczatek, Jakub
2022-06-22 15:31 ` David Marchand
2022-05-20 20:13 ` [PATCH 00/12] Fix compilation with gcc 12 Stephen Hemminger
2022-05-21 9:39 ` Morten Brørup
2022-06-15 8:49 ` David Marchand
2022-06-15 14:45 ` Stephen Hemminger
2022-06-15 14:59 ` Thomas Monjalon
2022-06-15 15:15 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220518101657.1230416-12-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@xilinx.com \
--cc=stable@dpdk.org \
--cc=thomas@monjalon.net \
--cc=wisamm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).