[dpdk-dev] librte_pmd_null: Fix build issue with gcc-4.7

Message ID 1425014298-14962-1-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Accepted, archived
Headers

Commit Message

Tetsuya Mukawa Feb. 27, 2015, 5:18 a.m. UTC
  This patch fixes following errors with gcc-4.7.

 lib/librte_pmd_null/rte_eth_null.c:302:28:
     error: array subscript is above array bounds

Reported-by: Mcnamara, John <john.mcnamara@intel.com>
Reported-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_pmd_null/rte_eth_null.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

John McNamara Feb. 27, 2015, 4:54 p.m. UTC | #1
> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Friday, February 27, 2015 5:18 AM
> To: dev@dpdk.org
> Cc: Mcnamara, John; stephen@networkplumber.org; Tetsuya Mukawa
> Subject: [PATCH] librte_pmd_null: Fix build issue with gcc-4.7
> 
> This patch fixes following errors with gcc-4.7.


Confirmed that this fixes the issue with 4.7.2.


Acked-by: John McNamara <john.mcnamara@intel.com>

--
  
Thomas Monjalon Feb. 27, 2015, 11:21 p.m. UTC | #2
> > This patch fixes following errors with gcc-4.7.
> 
> 
> Confirmed that this fixes the issue with 4.7.2.
> 
> Acked-by: John McNamara <john.mcnamara@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_pmd_null/rte_eth_null.c b/lib/librte_pmd_null/rte_eth_null.c
index bb10276..66b0d99 100644
--- a/lib/librte_pmd_null/rte_eth_null.c
+++ b/lib/librte_pmd_null/rte_eth_null.c
@@ -287,7 +287,7 @@  eth_dev_info(struct rte_eth_dev *dev,
 static void
 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 {
-	unsigned i;
+	unsigned i, num_stats;
 	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
 	const struct pmd_internals *internal;
 
@@ -296,15 +296,17 @@  eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 
 	internal = dev->data->dev_private;
 	memset(igb_stats, 0, sizeof(*igb_stats));
-	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
-			i < internal->nb_rx_queues; i++) {
+	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
+					internal->nb_rx_queues);
+	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_ipackets[i] =
 			internal->rx_null_queues[i].rx_pkts.cnt;
 		rx_total += igb_stats->q_ipackets[i];
 	}
 
-	for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
-			i < internal->nb_tx_queues; i++) {
+	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
+					internal->nb_tx_queues);
+	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_opackets[i] =
 			internal->tx_null_queues[i].tx_pkts.cnt;
 		igb_stats->q_errors[i] =