snprintf guarantees to always correctly place a null terminator
in the buffer string. So manually placing a null terminator
in a buffer right after a call to snprintf is redundant code.
Additionally, there is no need to use 'sizeof(buffer) - 1' in snprintf as this
means we are not using the last character in the buffer. 'sizeof(buffer)' is
enough.
Cc: stable@dpdk.org
Signed-off-by: Michael Santana <msantana@redhat.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
}
OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
}
OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
- snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
+ snprintf(mz_name, sizeof(mz_name), "%lx",
(unsigned long)rte_get_timer_cycles());
if (core_id == (unsigned int)LCORE_ID_ANY)
core_id = rte_get_master_lcore();
(unsigned long)rte_get_timer_cycles());
if (core_id == (unsigned int)LCORE_ID_ANY)
core_id = rte_get_master_lcore();
}
OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
}
OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
- snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
+ snprintf(mz_name, sizeof(mz_name), "%lx",
(unsigned long)rte_get_timer_cycles());
if (core_id == (unsigned int)LCORE_ID_ANY)
core_id = rte_get_master_lcore();
(unsigned long)rte_get_timer_cycles());
if (core_id == (unsigned int)LCORE_ID_ANY)
core_id = rte_get_master_lcore();
/* soft_id could have been used as memzone string, but soft_id is
* not currently used so it has no significance.
*/
/* soft_id could have been used as memzone string, but soft_id is
* not currently used so it has no significance.
*/
- snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
+ snprintf(mz_name, sizeof(mz_name), "%lx",
(unsigned long)rte_get_timer_cycles());
mz = rte_memzone_reserve_aligned(mz_name, QEDE_MAX_FDIR_PKT_LEN,
SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE);
(unsigned long)rte_get_timer_cycles());
mz = rte_memzone_reserve_aligned(mz_name, QEDE_MAX_FDIR_PKT_LEN,
SOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE);
char in[RTE_MAX(sizeof(ctx->yield), 256u)];
int ret;
char in[RTE_MAX(sizeof(ctx->yield), 256u)];
int ret;
- ret = snprintf(in, sizeof(in) - 1, "/sys/class/net/%s/%s",
+ ret = snprintf(in, sizeof(in), "/sys/class/net/%s/%s",
if_name, relpath);
if (ret == -1 || (size_t)ret >= sizeof(in))
return -ENOBUFS;
if_name, relpath);
if (ret == -1 || (size_t)ret >= sizeof(in))
return -ENOBUFS;
* by maximum 3 digits (plus an extra byte for safety) */
static char buffer[sizeof(MP_CLIENT_RXQ_NAME) + 2];
* by maximum 3 digits (plus an extra byte for safety) */
static char buffer[sizeof(MP_CLIENT_RXQ_NAME) + 2];
- snprintf(buffer, sizeof(buffer) - 1, MP_CLIENT_RXQ_NAME, id);
+ snprintf(buffer, sizeof(buffer), MP_CLIENT_RXQ_NAME, id);
*/
static char buffer[sizeof(MP_NODE_RXQ_NAME) + 2];
*/
static char buffer[sizeof(MP_NODE_RXQ_NAME) + 2];
- snprintf(buffer, sizeof(buffer) - 1, MP_NODE_RXQ_NAME, id);
+ snprintf(buffer, sizeof(buffer), MP_NODE_RXQ_NAME, id);
while ((dent = readdir(d)) != NULL) {
struct stat sb;
while ((dent = readdir(d)) != NULL) {
struct stat sb;
- snprintf(sopath, PATH_MAX-1, "%s/%s", path, dent->d_name);
- sopath[PATH_MAX-1] = 0;
+ snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
continue;
if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
continue;
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
- snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
+ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
RUNTIME_CONFIG_FNAME);
return buffer;
}
RUNTIME_CONFIG_FNAME);
return buffer;
}
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
- snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
+ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
MP_SOCKET_FNAME);
return buffer;
}
MP_SOCKET_FNAME);
return buffer;
}
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
- snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
+ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
HUGEPAGE_INFO_FNAME);
return buffer;
}
HUGEPAGE_INFO_FNAME);
return buffer;
}
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
{
static char buffer[PATH_MAX]; /* static so auto-zeroed */
- snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
+ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
HUGEPAGE_DATA_FNAME);
return buffer;
}
HUGEPAGE_DATA_FNAME);
return buffer;
}
{
snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
eal_get_hugefile_prefix(), f_id);
{
snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
eal_get_hugefile_prefix(), f_id);
- buffer[buflen - 1] = '\0';
- snprintf(fbarray_name, sizeof(fbarray_name) - 1, "%s_%p",
+ snprintf(fbarray_name, sizeof(fbarray_name), "%s_%p",
seg_name, va_addr);
/* create the backing fbarray */
seg_name, va_addr);
/* create the backing fbarray */
char heap_name[RTE_HEAP_NAME_MAX_LEN];
int socket_id = rte_socket_id_by_idx(i);
char heap_name[RTE_HEAP_NAME_MAX_LEN];
int socket_id = rte_socket_id_by_idx(i);
- snprintf(heap_name, sizeof(heap_name) - 1,
+ snprintf(heap_name, sizeof(heap_name),
"socket_%i", socket_id);
strlcpy(heap->name, heap_name, RTE_HEAP_NAME_MAX_LEN);
heap->socket_id = socket_id;
"socket_%i", socket_id);
strlcpy(heap->name, heap_name, RTE_HEAP_NAME_MAX_LEN);
heap->socket_id = socket_id;