Skip to contentSkip to conversation

fix incorrect snprintf args

PATCH Stephen Hemminger 2 participants 2 messages Jun 24, 2014 – Jun 27, 2014 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 20140624111333.721633f7-We1ePj4FEcvRI77zikRAJc56i+j3xesD0e7PPNI6Mm0@public.gmane.org

#2 lore raw

Now that snprintf is used, Gcc finds more uses of unsafe arguments. Fix where found. Some of these may have already been fixed by other patches on the mailing list.

---
v2 - no changes to this part

lib/librte_kni/rte_kni.c +4 -4
@@ -158,7 +158,7 @@ rte_kni_alloc(struct rte_mempool *pktmbu
 		}
 	}
 
-	snprintf(intf_name, RTE_KNI_NAMESIZE, conf->name);
+	snprintf(intf_name, RTE_KNI_NAMESIZE, "%s", conf->name);
 	snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "KNI_INFO_%s", intf_name);
 	mz = kni_memzone_reserve(mz_name, sizeof(struct rte_kni),
 				SOCKET_ID_ANY, 0);
@@ -184,8 +184,8 @@ rte_kni_alloc(struct rte_mempool *pktmbu
 	dev_info.group_id = conf->group_id;
 	dev_info.mbuf_size = conf->mbuf_size;
 
-	snprintf(ctx->name, RTE_KNI_NAMESIZE, intf_name);
-	snprintf(dev_info.name, RTE_KNI_NAMESIZE, intf_name);
+	snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name);
+	snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name);
 
 	RTE_LOG(INFO, KNI, "pci: %02x:%02x:%02x \t %02x:%02x\n",
 		dev_info.bus, dev_info.devid, dev_info.function,
@@ -291,7 +291,7 @@ rte_kni_release(struct rte_kni *kni)
 	if (!kni || !kni->in_use)
 		return -1;
 
-	snprintf(dev_info.name, sizeof(dev_info.name), kni->name);
+	snprintf(dev_info.name, sizeof(dev_info.name), "%s", kni->name);
 	if (ioctl(kni_fd, RTE_KNI_IOCTL_RELEASE, &dev_info) < 0) {
 		RTE_LOG(ERR, KNI, "Fail to release kni device\n");
 		return -1;
app/test/test_cmdline_etheraddr.c +1 -1
@@ -147,7 +147,7 @@ test_parse_etheraddr_invalid_param(void)
 
 	/* copy string to buffer */
 	snprintf(buf, sizeof(buf), "%s",
-			ether_addr_valid_strs[0]);
+		 ether_addr_valid_strs[0].str);
 
 	ret = cmdline_parse_etheraddr(NULL, buf, NULL);
 	if (ret == -1) {
app/test/test_eal_flags.c +1 -1
@@ -268,7 +268,7 @@ get_current_prefix(char * prefix, int si
 
 	/* copy string all the way from second char up to start of _config */
 	snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+		 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")), &buf[1]);
 
 	return prefix;
 }
app/test/test_mp_secondary.c +1 -1
@@ -103,7 +103,7 @@ get_current_prefix(char * prefix, int si
 
 	/* copy string all the way from second char up to start of _config */
 	snprintf(prefix, size, "%.*s",
-			strnlen(buf, sizeof(buf)) - sizeof("_config"), &buf[1]);
+		 (int)(strnlen(buf, sizeof(buf)) - sizeof("_config")), &buf[1]);
 
 	return prefix;
 }

A message that is not in the archive (sent off-list or not yet received): 20140624111438.11944cf0-We1ePj4FEcvRI77zikRAJc56i+j3xesD0e7PPNI6Mm0@public.gmane.org