diff mbox

[dpdk-dev] examples/load_balancer: fix build with gcc 5.1

Message ID 1433255928-11461-1-git-send-email-thomas.monjalon@6wind.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Thomas Monjalon June 2, 2015, 2:38 p.m. UTC
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(-)

Comments

Bruce Richardson June 3, 2015, 1:06 p.m. UTC | #1
On Tue, Jun 02, 2015 at 04:38:48PM +0200, Thomas Monjalon wrote:
> 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>
> ---

Acked-by: Bruce Richardson <bruce.richardson@intel.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
>
Thomas Monjalon June 3, 2015, 2:19 p.m. UTC | #2
2015-06-03 14:06, Bruce Richardson:
> On Tue, Jun 02, 2015 at 04:38:48PM +0200, Thomas Monjalon wrote:
> > 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>
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
diff mbox

Patch

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;