DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: remove rte_snprintf
@ 2014-09-26 14:39 Thomas Monjalon
  2014-09-26 15:14 ` Neil Horman
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Monjalon @ 2014-09-26 14:39 UTC (permalink / raw)
  To: dev

The function rte_snprintf() was deprecated in version 1.7.0
(commit 6f41fe75e2dd).
It's now totally removed.

Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
 app/test/Makefile                              |   7 --
 app/test/test_string_fns.c                     | 136 +------------------------
 lib/librte_eal/common/eal_common_string_fns.c  |  28 -----
 lib/librte_eal/common/include/rte_string_fns.h |  24 -----
 lib/librte_eal/common/include/rte_warnings.h   |   4 -
 5 files changed, 1 insertion(+), 198 deletions(-)

diff --git a/app/test/Makefile b/app/test/Makefile
index 210a7f6..822bbd4 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -133,13 +133,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_KVARGS) += test_kvargs.c
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 
-# Allow use of deprecated rte_snprintf in test_string_fns.c
-ifeq ($(CC), icc)
-CFLAGS_test_string_fns.o += -Wd1478
-else
-CFLAGS_test_string_fns.o += -Wno-deprecated-declarations
-endif
-
 # Disable warnings of deprecated-declarations in test_kni.c
 ifeq ($(CC), icc)
 CFLAGS_test_kni.o += -wd1478
diff --git a/app/test/test_string_fns.c b/app/test/test_string_fns.c
index 29bfe5b..39e6a9d 100644
--- a/app/test/test_string_fns.c
+++ b/app/test/test_string_fns.c
@@ -49,139 +49,6 @@
 #define DATA_BYTE 'a'
 
 static int
-test_rte_snprintf(void)
-{
-	/* =================================================
-	 * First test with a string that will fit in buffer
-	 * =================================================*/
-	do {
-		int retval;
-		const char source[] = "This is a string that will fit in buffer";
-		char buf[sizeof(source)+2]; /* make buffer big enough to fit string */
-
-		/* initialise buffer with characters so it can contain no nulls */
-		memset(buf, DATA_BYTE, sizeof(buf));
-
-		/* run rte_snprintf and check results */
-		retval = rte_snprintf(buf, sizeof(buf), "%s", source);
-		if (retval != sizeof(source) - 1) {
-			LOG("Error, retval = %d, expected = %u\n",
-					retval, (unsigned)sizeof(source));
-			return -1;
-		}
-		if (buf[retval] != '\0') {
-			LOG("Error, resultant is not null-terminated\n");
-			return -1;
-		}
-		if (memcmp(source, buf, sizeof(source)-1) != 0){
-			LOG("Error, corrupt data in buffer\n");
-			return -1;
-		}
-	} while (0);
-
-	do {
-		/* =================================================
-		 * Test with a string that will get truncated
-		 * =================================================*/
-		int retval;
-		const char source[] = "This is a long string that won't fit in buffer";
-		char buf[sizeof(source)/2]; /* make buffer half the size */
-
-		/* initialise buffer with characters so it can contain no nulls */
-		memset(buf, DATA_BYTE, sizeof(buf));
-
-		/* run rte_snprintf and check results */
-		retval = rte_snprintf(buf, sizeof(buf), "%s", source);
-		if (retval != sizeof(source) - 1) {
-			LOG("Error, retval = %d, expected = %u\n",
-					retval, (unsigned)sizeof(source));
-			return -1;
-		}
-		if (buf[sizeof(buf)-1] != '\0') {
-			LOG("Error, buffer is not null-terminated\n");
-			return -1;
-		}
-		if (memcmp(source, buf, sizeof(buf)-1) != 0){
-			LOG("Error, corrupt data in buffer\n");
-			return -1;
-		}
-	} while (0);
-
-	do {
-		/* ===========================================================
-		 * Test using zero-size buf to check how long a buffer we need
-		 * ===========================================================*/
-		int retval;
-		const char source[] = "This is a string";
-		char buf[10];
-
-		/* call with a zero-sized non-NULL buffer, should tell how big a buffer
-		 * we need */
-		retval = rte_snprintf(buf, 0, "%s", source);
-		if (retval != sizeof(source) - 1) {
-			LOG("Call with 0-length buffer does not return correct size."
-					"Expected: %zu, got: %d\n", sizeof(source), retval);
-			return -1;
-		}
-
-		/* call with a zero-sized NULL buffer, should tell how big a buffer
-		 * we need */
-		retval = rte_snprintf(NULL, 0, "%s", source);
-		if (retval != sizeof(source) - 1) {
-			LOG("Call with 0-length buffer does not return correct size."
-					"Expected: %zu, got: %d\n", sizeof(source), retval);
-			return -1;
-		}
-
-	} while (0);
-
-	do {
-		/* =================================================
-		 * Test with invalid parameter values
-		 * =================================================*/
-		const char source[] = "This is a string";
-		char buf[10];
-
-		/* call with buffer value set to NULL is EINVAL */
-		if (rte_snprintf(NULL, sizeof(buf), "%s\n", source) != -1 ||
-				errno != EINVAL) {
-			LOG("Failed to get suitable error when passing NULL buffer\n");
-			return -1;
-		}
-
-		memset(buf, DATA_BYTE, sizeof(buf));
-		/* call with a NULL format and zero-size should return error
-		 * without affecting the buffer */
-		if (rte_snprintf(buf, 0, NULL) != -1 ||
-				errno != EINVAL) {
-			LOG("Failed to get suitable error when passing NULL buffer\n");
-			return -1;
-		}
-		if (buf[0] != DATA_BYTE) {
-			LOG("Error, zero-length buffer modified after call with NULL"
-					" format string\n");
-			return -1;
-		}
-
-		/* call with a NULL format should return error but also null-terminate
-		 *  the buffer */
-		if (rte_snprintf(buf, sizeof(buf), NULL) != -1 ||
-				errno != EINVAL) {
-			LOG("Failed to get suitable error when passing NULL buffer\n");
-			return -1;
-		}
-		if (buf[0] != '\0') {
-			LOG("Error, buffer not null-terminated after call with NULL"
-					" format string\n");
-			return -1;
-		}
-	} while (0);
-
-	LOG("%s - PASSED\n", __func__);
-	return 0;
-}
-
-static int
 test_rte_strsplit(void)
 {
 	int i;
@@ -294,8 +161,7 @@ test_rte_strsplit(void)
 static int
 test_string_fns(void)
 {
-	if (test_rte_snprintf() < 0 ||
-			test_rte_strsplit() < 0)
+	if (test_rte_strsplit() < 0)
 		return -1;
 	return 0;
 }
diff --git a/lib/librte_eal/common/eal_common_string_fns.c b/lib/librte_eal/common/eal_common_string_fns.c
index fb0bbe8..125a3e2 100644
--- a/lib/librte_eal/common/eal_common_string_fns.c
+++ b/lib/librte_eal/common/eal_common_string_fns.c
@@ -38,34 +38,6 @@
 
 #include <rte_string_fns.h>
 
-/* safe version os snprintf */
-int
-rte_snprintf(char *buffer, int buflen, const char *format, ...)
-{
-	int len;
-	va_list ap;
-
-	if (buffer == NULL && buflen != 0)
-		goto einval_error;
-	if (format == NULL) {
-		if (buflen > 0)
-			buffer[0] = '\0';
-		goto einval_error;
-	}
-
-	va_start(ap, format);
-	len = vsnprintf(buffer, buflen, format, ap);
-	va_end(ap);
-	if (len >= buflen && buflen > 0)
-		buffer[buflen - 1] = '\0';
-
-	return len;
-
-einval_error:
-	errno = EINVAL;
-	return -1;
-}
-
 /* split string into tokens */
 int
 rte_strsplit(char *string, int stringlen,
diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h
index cf96b2c..cfca2f8 100644
--- a/lib/librte_eal/common/include/rte_string_fns.h
+++ b/lib/librte_eal/common/include/rte_string_fns.h
@@ -45,30 +45,6 @@ extern "C" {
 #endif
 
 /**
- * This functio is deprecated and just for backward compatibility.
- * It is just an alternate version of snprintf.
- *
- * @param buffer
- *   The buffer into which the output is to be written
- *
- * @param buflen
- *   The size of the output buffer
- *
- * @param format
- *   The format string to be printed to the buffer
- *
- * @return
- *   The number of characters written to the buffer, or if the string has been
- *   truncated, the number of characters which would have been written had the
- *   buffer been sufficiently big.
- *
- */
-int
-rte_snprintf(char *buffer, int buflen, const char *format, ...)
-	__attribute__((format(printf,3,4)))
-	__attribute__((deprecated));
-
-/**
  * Takes string "string" parameter and splits it at character "delim"
  * up to maxtokens-1 times - to give "maxtokens" resulting tokens. Like
  * strtok or strsep functions, this modifies its input string, by replacing
diff --git a/lib/librte_eal/common/include/rte_warnings.h b/lib/librte_eal/common/include/rte_warnings.h
index 423e6fb..da80877 100644
--- a/lib/librte_eal/common/include/rte_warnings.h
+++ b/lib/librte_eal/common/include/rte_warnings.h
@@ -54,10 +54,6 @@
 #include <dirent.h>
 #endif
 
-/* rte_snprintf uses snprintf, so include its definition before we poison the
- * functions, otherwise we'll get an error in it. */
-#include <rte_string_fns.h>
-
 /* the following function are deemed not fully secure for use e.g. they
  * do not always null-terminate arguments */
 #pragma GCC poison sprintf strtok snprintf vsnprintf
-- 
2.0.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-29 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-26 14:39 [dpdk-dev] [PATCH] eal: remove rte_snprintf Thomas Monjalon
2014-09-26 15:14 ` Neil Horman
2014-09-29 13:05   ` Thomas Monjalon

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).