Bruce Richardson 27b549c12d examples/multi_process: fix build on Ubuntu 20.04
Two warnings are reported by gcc 9.3.0 on Ubuntu 20.04.

When producing a printable mac address the buffer was appropriately sized
for holding the mac address exactly, but the actual snprintf included a
'\n' character at the end, which means that the snprintf technically is
getting truncated i.e. the \n would not be added due to lack of space.
This gets flagged as a problem by modern versions of gcc, e.g. on Ubuntu
20.04.

main.c:77:37: warning: ‘__builtin___snprintf_chk’ output truncated
  before the last format character [-Wformat-truncation=]
   77 |     "%02x:%02x:%02x:%02x:%02x:%02x\n",
      |                                     ^

Since the \n is getting stripped anyway, we can fix the issue by just
removing it. In the process we can switch to using the standard ethernet
address formatting function from rte_ether.h.

The other warning is about possible string truncation when getting the
RX queue name:

In file included from init.c:36:
init.c: In function ‘init’:
../shared/common.h:38:28: warning: ‘%u’ directive output may be truncated
  writing between 1 and 10 bytes into a region of size 8
  [-Wformat-truncation=]
   38 | #define MP_CLIENT_RXQ_NAME "MProc_Client_%u_RX"
      |                            ^~~~~~~~~~~~~~~~~~~~
../shared/common.h:52:35: note: in expansion of macro ‘MP_CLIENT_RXQ_NAME’
   52 |  snprintf(buffer, sizeof(buffer), MP_CLIENT_RXQ_NAME, id);
      |                                   ^~~~~~~~~~~~~~~~~~

This is a false positive, as the value of the "id" is limited to 255,
being stored in the app as a uint8_t value, removing the possibility of
the %u being replaced by anything other then 3 characters max (rather than
up to 10 as thought by the compiler). Therefore, the warning can be easily
removed by changing the type of the "id" parameter to the local function
from "unsigned" to "uint8_t" also, ensuring the compiler is aware of the
range limit.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Radu Nicolau <radu.nicolau@intel.com>
2020-10-30 14:54:50 +01:00

59 lines
1.7 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2010-2014 Intel Corporation
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#define MAX_CLIENTS 16
/*
* Shared port info, including statistics information for display by server.
* Structure will be put in a memzone.
* - All port id values share one cache line as this data will be read-only
* during operation.
* - All rx statistic values share cache lines, as this data is written only
* by the server process. (rare reads by stats display)
* - The tx statistics have values for all ports per cache line, but the stats
* themselves are written by the clients, so we have a distinct set, on different
* cache lines for each client to use.
*/
struct rx_stats{
uint64_t rx[RTE_MAX_ETHPORTS];
} __rte_cache_aligned;
struct tx_stats{
uint64_t tx[RTE_MAX_ETHPORTS];
uint64_t tx_drop[RTE_MAX_ETHPORTS];
} __rte_cache_aligned;
struct port_info {
uint16_t num_ports;
uint16_t id[RTE_MAX_ETHPORTS];
volatile struct rx_stats rx_stats;
volatile struct tx_stats tx_stats[MAX_CLIENTS];
};
/* define common names for structures shared between server and client */
#define MP_CLIENT_RXQ_NAME "MProc_Client_%u_RX"
#define PKTMBUF_POOL_NAME "MProc_pktmbuf_pool"
#define MZ_PORT_INFO "MProc_port_info"
/*
* Given the rx queue name template above, get the queue name
*/
static inline const char *
get_rx_queue_name(uint8_t id)
{
/* buffer for return value. Size calculated by %u being replaced
* by maximum 3 digits (plus an extra byte for safety) */
static char buffer[sizeof(MP_CLIENT_RXQ_NAME) + 2];
snprintf(buffer, sizeof(buffer), MP_CLIENT_RXQ_NAME, id);
return buffer;
}
#define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
#endif