From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] examples/load_balancer: fix build with gcc 5.1
Date: Tue, 2 Jun 2015 16:38:48 +0200 [thread overview]
Message-ID: <1433255928-11461-1-git-send-email-thomas.monjalon@6wind.com> (raw)
GCC 5.1 detects more out-of-bounds accesses:
error: array subscript is above array bounds [-Werror=array-bounds]
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
examples/load_balancer/config.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/examples/load_balancer/config.c b/examples/load_balancer/config.c
index 35f1441..3f6ddee 100644
--- a/examples/load_balancer/config.c
+++ b/examples/load_balancer/config.c
@@ -231,7 +231,9 @@ parse_arg_rx(const char *arg)
return -7;
}
lp->type = e_APP_LCORE_IO;
- for (i = 0; i < lp->io.rx.n_nic_queues; i ++) {
+ const size_t n_queues = RTE_MIN(lp->io.rx.n_nic_queues,
+ RTE_DIM(lp->io.rx.nic_queues));
+ for (i = 0; i < n_queues; i ++) {
if ((lp->io.rx.nic_queues[i].port == port) &&
(lp->io.rx.nic_queues[i].queue == queue)) {
return -8;
@@ -308,7 +310,9 @@ parse_arg_tx(const char *arg)
return -7;
}
lp->type = e_APP_LCORE_IO;
- for (i = 0; i < lp->io.tx.n_nic_ports; i ++) {
+ const size_t n_ports = RTE_MIN(lp->io.tx.n_nic_ports,
+ RTE_DIM(lp->io.tx.nic_ports));
+ for (i = 0; i < n_ports; i ++) {
if (lp->io.tx.nic_ports[i] == port) {
return -8;
}
@@ -791,7 +795,9 @@ app_get_lcore_for_nic_rx(uint8_t port, uint8_t queue, uint32_t *lcore_out)
continue;
}
- for (i = 0; i < lp->rx.n_nic_queues; i ++) {
+ const size_t n_queues = RTE_MIN(lp->rx.n_nic_queues,
+ RTE_DIM(lp->rx.nic_queues));
+ for (i = 0; i < n_queues; i ++) {
if ((lp->rx.nic_queues[i].port == port) &&
(lp->rx.nic_queues[i].queue == queue)) {
*lcore_out = lcore;
@@ -816,7 +822,9 @@ app_get_lcore_for_nic_tx(uint8_t port, uint32_t *lcore_out)
continue;
}
- for (i = 0; i < lp->tx.n_nic_ports; i ++) {
+ const size_t n_ports = RTE_MIN(lp->tx.n_nic_ports,
+ RTE_DIM(lp->tx.nic_ports));
+ for (i = 0; i < n_ports; i ++) {
if (lp->tx.nic_ports[i] == port) {
*lcore_out = lcore;
return 0;
--
2.4.2
next reply other threads:[~2015-06-02 14:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-02 14:38 Thomas Monjalon [this message]
2015-06-03 13:06 ` Bruce Richardson
2015-06-03 14:19 ` Thomas Monjalon
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=1433255928-11461-1-git-send-email-thomas.monjalon@6wind.com \
--to=thomas.monjalon@6wind.com \
--cc=dev@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).