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>,
	Brian Dooley <brian.dooley@intel.com>,
	Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>,
	Jerin Jacob <jerinj@marvell.com>,
	Kiran Kumar K <kirankumark@marvell.com>,
	Nithin Dabilpuram <ndabilpuram@marvell.com>,
	Cristian Dumitrescu <cristian.dumitrescu@intel.com>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Chenbo Xia <chenbo.xia@intel.com>
Subject: [PATCH 02/25] examples: use strlcpy instead of snprintf
Date: Thu,  1 Jun 2023 08:00:43 -0700	[thread overview]
Message-ID: <20230601150106.18375-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20230601150106.18375-1-stephen@networkplumber.org>

Replace snprintf() with strlcpy() where possible.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/fips_validation/fips_validation.c | 8 ++++----
 examples/l3fwd-graph/main.c                | 2 +-
 examples/pipeline/cli.c                    | 2 +-
 examples/vhost_blk/vhost_blk.c             | 5 ++---
 4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c
index f840804009ed..6e913898074d 100644
--- a/examples/fips_validation/fips_validation.c
+++ b/examples/fips_validation/fips_validation.c
@@ -505,8 +505,8 @@ fips_test_parse_one_json_group(void)
 
 			switch (json_typeof(param)) {
 			case JSON_STRING:
-				snprintf(json_value, sizeof(json_value), "%s",
-						 json_string_value(param));
+				strlcpy(json_value, json_string_value(param),
+					sizeof(json_value));
 				break;
 
 			case JSON_INTEGER:
@@ -550,8 +550,8 @@ fips_test_parse_one_json_case(void)
 
 		switch (json_typeof(param)) {
 		case JSON_STRING:
-			snprintf(info.one_line_text, MAX_LINE_CHAR, "%s",
-					 json_string_value(param));
+			strlcpy(info.one_line_text, json_string_value(param),
+				MAX_LINE_CHAR);
 			break;
 
 		case JSON_INTEGER:
diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c
index 5feeab4f0fb0..ee8f247108ad 100644
--- a/examples/l3fwd-graph/main.c
+++ b/examples/l3fwd-graph/main.c
@@ -546,7 +546,7 @@ parse_args(int argc, char **argv)
 			break;
 
 		case CMD_LINE_OPT_PCAP_FILENAME_CAP:
-			rte_strlcpy(pcap_filename, optarg,
+			strlcpy(pcap_filename, optarg,
 				    sizeof(pcap_filename));
 			printf("Pcap file name: %s\n", pcap_filename);
 			break;
diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 2ae6cc579ff2..514b6d779212 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -3164,7 +3164,7 @@ cmd_ipsec_sa_add(char **tokens,
 			goto free;
 		}
 
-		snprintf(out, out_size, "%s", line);
+		strlcpy(out, line, out_size);
 		out_size -= strlen(out);
 		out += strlen(out);
 
diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c
index 3709d7ed06ba..3b05df390cce 100644
--- a/examples/vhost_blk/vhost_blk.c
+++ b/examples/vhost_blk/vhost_blk.c
@@ -771,9 +771,8 @@ vhost_blk_bdev_construct(const char *bdev_name,
 	if (!bdev)
 		return NULL;
 
-	snprintf(bdev->name, sizeof(bdev->name), "%s", bdev_name);
-	snprintf(bdev->product_name, sizeof(bdev->product_name), "%s",
-		 bdev_serial);
+	strlcpy(bdev->name, bdev_name, sizeof(bdev->name));
+	strlcpy(bdev->product_name, bdev_serial, sizeof(bdev->product_name));
 	bdev->blocklen = blk_size;
 	bdev->blockcnt = blk_cnt;
 	bdev->write_cache = wce_enable;
-- 
2.39.2


  parent 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 ` [PATCH 01/25] app: use strlcpy in tests Stephen Hemminger
2023-06-01 15:00 ` Stephen Hemminger [this message]
2023-06-01 15:00 ` [PATCH 03/25] lib: use strlcpy instead of snprintf 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-3-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=brian.dooley@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=gmuthukrishn@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=kirankumark@marvell.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=ndabilpuram@marvell.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).