DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] examples/load_balancer: fix build with gcc 5.1
@ 2015-06-02 14:38 Thomas Monjalon
  2015-06-03 13:06 ` Bruce Richardson
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Monjalon @ 2015-06-02 14:38 UTC (permalink / raw)
  To: dev

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-03 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-02 14:38 [dpdk-dev] [PATCH] examples/load_balancer: fix build with gcc 5.1 Thomas Monjalon
2015-06-03 13:06 ` Bruce Richardson
2015-06-03 14:19   ` Thomas Monjalon

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).