DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Nicolas Chautru <nicolas.chautru@intel.com>,
	Ori Kam <orika@nvidia.com>,
	Aman Singh <aman.deep.singh@intel.com>,
	Yuying Zhang <yuying.zhang@intel.com>,
	Jerin Jacob <jerinj@marvell.com>,
	Kiran Kumar K <kirankumark@marvell.com>,
	Nithin Dabilpuram <ndabilpuram@marvell.com>
Subject: [PATCH 01/25] app: use strlcpy in tests
Date: Thu,  1 Jun 2023 08:00:42 -0700	[thread overview]
Message-ID: <20230601150106.18375-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20230601150106.18375-1-stephen@networkplumber.org>

Prefer using strlcpy over snprintf().

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test-bbdev/main.c       |  5 ++---
 app/test-pmd/cmdline_flow.c |  6 +++---
 app/test/process.h          |  2 +-
 app/test/test_graph_perf.c  | 29 ++++++++++++++++-------------
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c
index ec830eb32bc8..b1f2d79f4b07 100644
--- a/app/test-bbdev/main.c
+++ b/app/test-bbdev/main.c
@@ -251,9 +251,8 @@ parse_args(int argc, char **argv, struct test_params *tp)
 			TEST_ASSERT(strlen(optarg) > 0,
 					"Config file name is null");
 
-			snprintf(tp->test_vector_filename,
-					sizeof(tp->test_vector_filename),
-					"%s", optarg);
+			strlcpy(tp->test_vector_filename, optarg,
+				sizeof(tp->test_vector_filename));
 			break;
 		case 's':
 			TEST_ASSERT(strlen(optarg) > 0,
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 58939ec321d6..40f67d126b4b 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -10028,7 +10028,7 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
 		char tmp[3], *end = tmp;
 		uint32_t read_lim = left & 1 ? 1 : 2;
 
-		snprintf(tmp, read_lim + 1, "%s", src);
+		strlcpy(tmp, src, read_lim + 1);
 		*dst = strtoul(tmp, &end, 16);
 		if (*end) {
 			*dst = 0;
@@ -11404,7 +11404,7 @@ cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
 	if (!size)
 		return -1;
 	/* Set token type and update global help with details. */
-	strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
+	strlcpy(dst, token->type ? : "TOKEN", size);
 	if (token->help)
 		cmd_flow.help_str = token->help;
 	else
@@ -12220,7 +12220,7 @@ cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
 	if (!size)
 		return -1;
 	/* Set token type and update global help with details. */
-	snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
+	strlcpy(dst, token->type ? : "TOKEN", size);
 	if (token->help)
 		cmd_set_raw.help_str = token->help;
 	else
diff --git a/app/test/process.h b/app/test/process.h
index 1f073b9c5c2a..e2bdecb9c807 100644
--- a/app/test/process.h
+++ b/app/test/process.h
@@ -176,7 +176,7 @@ get_current_prefix(char *prefix, int size)
 		return NULL;
 
 	/* get the prefix */
-	snprintf(prefix, size, "%s", basename(dirname(buf)));
+	strlcpy(prefix, basename(dirname(buf)), size);
 
 	return prefix;
 }
diff --git a/app/test/test_graph_perf.c b/app/test/test_graph_perf.c
index c5b463f700cd..521d4077600d 100644
--- a/app/test/test_graph_perf.c
+++ b/app/test/test_graph_perf.c
@@ -294,8 +294,9 @@ graph_node_count_edges(uint32_t stage, uint16_t node, uint16_t nodes_per_stage,
 	for (i = 0; i < nodes_per_stage && edges < MAX_EDGES_PER_NODE; i++) {
 		if (edge_map[stage + 1][i][node]) {
 			ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE);
-			snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(node_map[stage + 1][i]));
+			strlcpy(ename[edges],
+				rte_node_id_to_name(node_map[stage + 1][i]),
+				RTE_NODE_NAMESIZE);
 			node_data->next_nodes[edges] = node_map[stage + 1][i];
 			node_data->next_percentage[edges] =
 				edge_map[stage + 1][i][node];
@@ -405,9 +406,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 				graph_data->nb_nodes++;
 				goto pattern_name_free;
 			}
-			snprintf(node_patterns[graph_data->nb_nodes],
-				 RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(node_map[i][j]));
+			strlcpy(node_patterns[graph_data->nb_nodes],
+				rte_node_id_to_name(node_map[i][j]),
+				RTE_NODE_NAMESIZE);
 			node_data =
 				&graph_data->node_data[graph_data->nb_nodes];
 			node_data->node_id = node_map[i][j];
@@ -467,8 +468,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			graph_data->nb_nodes++;
 			goto pattern_name_free;
 		}
-		snprintf(node_patterns[graph_data->nb_nodes], RTE_NODE_NAMESIZE,
-			 "%s", rte_node_id_to_name(src_nodes[i]));
+		strlcpy(node_patterns[graph_data->nb_nodes],
+			rte_node_id_to_name(src_nodes[i]), RTE_NODE_NAMESIZE);
 		node_data = &graph_data->node_data[graph_data->nb_nodes];
 		node_data->node_id = src_nodes[i];
 		node_data->is_sink = false;
@@ -479,8 +480,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			if (!src_map[i][j])
 				continue;
 			ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE);
-			snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(node_map[0][j]));
+			strlcpy(ename[edges],
+				rte_node_id_to_name(node_map[0][j]),
+				RTE_NODE_NAMESIZE);
 			node_data->next_nodes[edges] = node_map[0][j];
 			node_data->next_percentage[edges] = src_map[i][j];
 			edges++;
@@ -524,8 +526,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			graph_data->nb_nodes++;
 			goto pattern_name_free;
 		}
-		snprintf(node_patterns[graph_data->nb_nodes], RTE_NODE_NAMESIZE,
-			 "%s", rte_node_id_to_name(snk_nodes[i]));
+		strlcpy(node_patterns[graph_data->nb_nodes],
+			rte_node_id_to_name(snk_nodes[i]), RTE_NODE_NAMESIZE);
 		node_data = &graph_data->node_data[graph_data->nb_nodes];
 		node_data->node_id = snk_nodes[i];
 		node_data->is_sink = true;
@@ -543,8 +545,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			if (!snk_map[i][j])
 				continue;
 			ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE);
-			snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(snk_nodes[j]));
+			strlcpy(ename[edges],
+				rte_node_id_to_name(snk_nodes[j]),
+				RTE_NODE_NAMESIZE);
 			node_data->next_nodes[edges] = snk_nodes[j];
 			node_data->next_percentage[edges] = snk_map[i][j];
 			edges++;
-- 
2.39.2


  reply	other threads:[~2023-06-01 15:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
2023-06-01 15:00 ` Stephen Hemminger [this message]
2023-06-01 15:00 ` [PATCH 02/25] examples: use strlcpy instead of snprintf Stephen Hemminger
2023-06-01 15:00 ` [PATCH 03/25] lib: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy Stephen Hemminger
2023-06-02  6:04   ` Xu, Rosen
2023-06-01 15:00 ` [PATCH 05/25] common/cnxk: replace snprint " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 06/25] common/mlx5: replace snprintf " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 07/25] drivers/gpu: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 08/25] crypto/ipsec_mb: remove unnecessary snprintf Stephen Hemminger
2023-06-01 15:00 ` [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy Stephen Hemminger
2023-06-02  4:24   ` Hemant Agrawal
2023-06-01 15:00 ` [PATCH 10/25] event/cnxk: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 11/25] net/atlantic: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 12/25] net/axgbe: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 13/25] net/bnxt: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 14/25] net/cpfl: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 15/25] net/cxgbe: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 16/25] net/dpaa*: " Stephen Hemminger
2023-06-02  4:24   ` Hemant Agrawal
2023-06-01 15:00 ` [PATCH 17/25] net/hinic: replace snptintf " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 18/25] net/hns3: replace snprint " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 19/25] net/intel: replace snprintf " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 20/25] net/ionic: " Stephen Hemminger
2023-06-02  6:05   ` Xu, Rosen
2023-06-01 15:01 ` [PATCH 21/25] net/mlx5: " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 22/25] net/nfp: " Stephen Hemminger
2023-06-05 11:10   ` Niklas Söderlund
2023-06-01 15:01 ` [PATCH 23/25] net/ngbe: " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 24/25] net/qede: " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 25/25] net/txgbe: " Stephen Hemminger
2023-06-02 20:01 ` [PATCH 00/25] " Tyler Retzlaff

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=20230601150106.18375-2-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=kirankumark@marvell.com \
    --cc=ndabilpuram@marvell.com \
    --cc=nicolas.chautru@intel.com \
    --cc=orika@nvidia.com \
    --cc=yuying.zhang@intel.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).