eal: remove rte_snprintf
The function rte_snprintf() was deprecated in version 1.7.0
(commit 6f41fe75e2
).
It's now totally removed.
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
This commit is contained in:
parent
accf99308b
commit
3185322809
@ -137,13 +137,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_KVARGS) += test_kvargs.c
|
|||||||
CFLAGS += -O3
|
CFLAGS += -O3
|
||||||
CFLAGS += $(WERROR_FLAGS)
|
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
|
# Disable warnings of deprecated-declarations in test_kni.c
|
||||||
ifeq ($(CC), icc)
|
ifeq ($(CC), icc)
|
||||||
CFLAGS_test_kni.o += -wd1478
|
CFLAGS_test_kni.o += -wd1478
|
||||||
|
@ -48,139 +48,6 @@
|
|||||||
|
|
||||||
#define DATA_BYTE 'a'
|
#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
|
static int
|
||||||
test_rte_strsplit(void)
|
test_rte_strsplit(void)
|
||||||
{
|
{
|
||||||
@ -294,8 +161,7 @@ test_rte_strsplit(void)
|
|||||||
static int
|
static int
|
||||||
test_string_fns(void)
|
test_string_fns(void)
|
||||||
{
|
{
|
||||||
if (test_rte_snprintf() < 0 ||
|
if (test_rte_strsplit() < 0)
|
||||||
test_rte_strsplit() < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -38,34 +38,6 @@
|
|||||||
|
|
||||||
#include <rte_string_fns.h>
|
#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 */
|
/* split string into tokens */
|
||||||
int
|
int
|
||||||
rte_strsplit(char *string, int stringlen,
|
rte_strsplit(char *string, int stringlen,
|
||||||
|
@ -44,30 +44,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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"
|
* Takes string "string" parameter and splits it at character "delim"
|
||||||
* up to maxtokens-1 times - to give "maxtokens" resulting tokens. Like
|
* up to maxtokens-1 times - to give "maxtokens" resulting tokens. Like
|
||||||
|
@ -54,10 +54,6 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#endif
|
#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
|
/* the following function are deemed not fully secure for use e.g. they
|
||||||
* do not always null-terminate arguments */
|
* do not always null-terminate arguments */
|
||||||
#pragma GCC poison sprintf strtok snprintf vsnprintf
|
#pragma GCC poison sprintf strtok snprintf vsnprintf
|
||||||
|
Loading…
Reference in New Issue
Block a user