[03/25] lib: use strlcpy instead of snprintf

Message ID 20230601150106.18375-4-stephen@networkplumber.org (mailing list archive)
State Rejected
Delegated to: Thomas Monjalon
Headers
Series replace snprintf with strlcpy |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger June 1, 2023, 3 p.m. UTC
  Replace snprintf with strlcpy where possible.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/bbdev/rte_bbdev.c |  2 +-
 lib/ethdev/sff_8636.c | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
  

Patch

diff --git a/lib/bbdev/rte_bbdev.c b/lib/bbdev/rte_bbdev.c
index 581509b5a213..7cc126a0e7be 100644
--- a/lib/bbdev/rte_bbdev.c
+++ b/lib/bbdev/rte_bbdev.c
@@ -212,7 +212,7 @@  rte_bbdev_allocate(const char *name)
 	bbdev->data->dev_id = dev_id;
 	bbdev->state = RTE_BBDEV_INITIALIZED;
 
-	ret = snprintf(bbdev->data->name, RTE_BBDEV_NAME_MAX_LEN, "%s", name);
+	ret = strlcpy(bbdev->data->name, name, RTE_BBDEV_NAME_MAX_LEN);
 	if ((ret < 0) || (ret >= RTE_BBDEV_NAME_MAX_LEN)) {
 		rte_bbdev_log(ERR, "Copying device name \"%s\" failed", name);
 		return NULL;
diff --git a/lib/ethdev/sff_8636.c b/lib/ethdev/sff_8636.c
index 6b65f47efedf..a623e0d065d8 100644
--- a/lib/ethdev/sff_8636.c
+++ b/lib/ethdev/sff_8636.c
@@ -203,16 +203,19 @@  static void sff_8636_show_ext_identifier(const uint8_t *data, struct rte_tel_dat
 
 	switch (data[SFF_8636_EXT_ID_OFFSET] & SFF_8636_EXT_ID_EPWR_CLASS_MASK) {
 	case SFF_8636_EXT_ID_PWR_CLASS_LEGACY:
-		snprintf(val_string, sizeof(val_string), "%s", "");
+		strlcpy(val_string, "", sizeof(val_string));
 		break;
 	case SFF_8636_EXT_ID_PWR_CLASS_5:
-		snprintf(val_string, sizeof(val_string), "%s", "4.0W max. Power consumption, ");
+		strlcpy(val_string, "4.0W max. Power consumption, ",
+			sizeof(val_string));
 		break;
 	case SFF_8636_EXT_ID_PWR_CLASS_6:
-		snprintf(val_string, sizeof(val_string), "%s", "4.5W max. Power consumption, ");
+		strlcpy(val_string, "4.5W max. Power consumption, ",
+			sizeof(val_string));
 		break;
 	case SFF_8636_EXT_ID_PWR_CLASS_7:
-		snprintf(val_string, sizeof(val_string), "%s", "5.0W max. Power consumption, ");
+		strlcpy(val_string, "5.0W max. Power consumption, ",
+			sizeof(val_string));
 		break;
 	}