[v2,4/4] examples/mp_server: clear string truncation warning
diff mbox series

Message ID 20200821171017.50531-5-bruce.richardson@intel.com
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • fixes for example app builds
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Aug. 21, 2020, 5:10 p.m. UTC
Compiling with GCC 9.3 on Ubuntu 20.04 gives a warning 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.

Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 examples/multi_process/client_server_mp/shared/common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nicolau, Radu Oct. 9, 2020, 11:21 a.m. UTC | #1
On 8/21/2020 6:10 PM, Bruce Richardson wrote:
> Compiling with GCC 9.3 on Ubuntu 20.04 gives a warning 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.
>
> Cc: stable@dpdk.org
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
Acked-by: Radu Nicolau <radu.nicolau@intel.com>

Patch
diff mbox series

diff --git a/examples/multi_process/client_server_mp/shared/common.h b/examples/multi_process/client_server_mp/shared/common.h
index 6dd43fcac2..76beca0101 100644
--- a/examples/multi_process/client_server_mp/shared/common.h
+++ b/examples/multi_process/client_server_mp/shared/common.h
@@ -43,7 +43,7 @@  struct port_info {
  * Given the rx queue name template above, get the queue name
  */
 static inline const char *
-get_rx_queue_name(unsigned id)
+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) */