From patchwork Tue Jun 2 14:38:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 5088 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id D2A51C350; Tue, 2 Jun 2015 16:39:42 +0200 (CEST) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by dpdk.org (Postfix) with ESMTP id B2E5EC34A for ; Tue, 2 Jun 2015 16:39:41 +0200 (CEST) Received: by wikd7 with SMTP id d7so15757845wik.0 for ; Tue, 02 Jun 2015 07:39:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=/kXyq120++9OzsGPUM4xdv1on9G85XEULK07aSOkIsI=; b=b6jf4D0rFLJXEGNW5ouGs6geshBiuWxstOIIZ5JLUWSohgIOuuYUJ1zfOLIGEqoKJa BQEEkUy/QLyE04F35W7KNW2sICm2BMP2UY91SA7r9ElB1Xy/qy9zlNZHMI7KdUXibmVp mKjwPHX0U7u9vydqhl4Oks4BpXVXbbNifTFEY889A48EeRIFEjSv5gyaynh+uTfFKHSO cdENAAfLm/XncH2FgZxsAASf3GxlA4PfuIlfvIMYlB2WXfx4TD+GQhbTp7bcXXDu2Urq jGwQyXnaPU/3SgvH7/PjigNrD3dSWNAmr2eMRdNkgmbneDpZvGHpQYT5MGjz/hEy1Dgk blxg== X-Gm-Message-State: ALoCoQlKvimnQr26ShEnwqtl67PxObeyYvP0BOAcfmckWCTfWWhTQ9TpHHJmRaCe+fzXj3iAcUiy X-Received: by 10.194.5.135 with SMTP id s7mr52429142wjs.115.1433255981567; Tue, 02 Jun 2015 07:39:41 -0700 (PDT) Received: from localhost.localdomain (136-92-190-109.dsl.ovh.fr. [109.190.92.136]) by mx.google.com with ESMTPSA id d3sm9148173wic.1.2015.06.02.07.39.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jun 2015 07:39:40 -0700 (PDT) From: Thomas Monjalon To: dev@dpdk.org Date: Tue, 2 Jun 2015 16:38:48 +0200 Message-Id: <1433255928-11461-1-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.4.2 Subject: [dpdk-dev] [PATCH] examples/load_balancer: fix build with gcc 5.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "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 Acked-by: Bruce Richardson --- 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;