patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	stable@dpdk.org, Radu Nicolau <radu.nicolau@intel.com>,
	Anatoly Burakov <anatoly.burakov@intel.com>
Subject: [dpdk-stable] [PATCH v3 3/3] examples/mp_server: clear string truncation warning
Date: Wed, 28 Oct 2020 16:27:02 +0000	[thread overview]
Message-ID: <20201028162702.969509-4-bruce.richardson@intel.com> (raw)
In-Reply-To: <20201028162702.969509-1-bruce.richardson@intel.com>

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>
---
 examples/multi_process/client_server_mp/shared/common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/examples/multi_process/client_server_mp/shared/common.h b/examples/multi_process/client_server_mp/shared/common.h
index 6dd43fcac..76beca010 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) */
-- 
2.25.1


      parent reply	other threads:[~2020-10-28 16:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200814110045.217724-1-bruce.richardson@intel.com>
2020-08-14 11:00 ` [dpdk-stable] [PATCH 1/4] power: make guest channel headers public Bruce Richardson
2020-08-14 11:05   ` Bruce Richardson
2020-08-14 11:00 ` [dpdk-stable] [PATCH 2/4] examples/vm_power_manager: fix string truncation warning Bruce Richardson
2020-08-14 11:00 ` [dpdk-stable] [PATCH 3/4] examples/mp_server: fix snprintf overflow Bruce Richardson
2020-08-14 15:01   ` [dpdk-stable] [dpdk-dev] " Stephen Hemminger
2020-08-14 11:00 ` [dpdk-stable] [PATCH 4/4] examples/mp_server: clear string truncation warning Bruce Richardson
     [not found] ` <20200821171017.50531-1-bruce.richardson@intel.com>
2020-08-21 17:10   ` [dpdk-stable] [PATCH v2 1/4] power: make guest channel headers public Bruce Richardson
2020-08-26 10:08     ` David Hunt
2020-10-05 21:44     ` Thomas Monjalon
2020-08-21 17:10   ` [dpdk-stable] [PATCH v2 2/4] examples/vm_power_manager: fix string truncation warning Bruce Richardson
2020-08-26 10:09     ` David Hunt
2020-08-21 17:10   ` [dpdk-stable] [PATCH v2 3/4] examples/mp_server: fix snprintf overflow Bruce Richardson
2020-10-09 11:22     ` [dpdk-stable] [dpdk-dev] " Nicolau, Radu
2020-08-21 17:10   ` [dpdk-stable] [PATCH v2 4/4] examples/mp_server: clear string truncation warning Bruce Richardson
2020-10-09 11:21     ` [dpdk-stable] [dpdk-dev] " Nicolau, Radu
     [not found] ` <20201028162702.969509-1-bruce.richardson@intel.com>
2020-10-28 16:27   ` [dpdk-stable] [PATCH v3 1/3] examples/vm_power_manager: fix " Bruce Richardson
2020-10-28 16:27   ` [dpdk-stable] [PATCH v3 2/3] examples/mp_server: fix snprintf overflow Bruce Richardson
2020-10-28 16:27   ` Bruce Richardson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201028162702.969509-4-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=radu.nicolau@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).