[dpdk-dev] [PATCH 4/4] null: fix compile on Fedora 22 (GCC 5.1)

Bruce Richardson bruce.richardson at intel.com
Fri May 29 14:53:47 CEST 2015


On Fedora 22, with GCC 5.1, errors are reported due to array accesses
being potentially out of bounds. This commit fixes this by adding in an
extra bounds check to the loop counter.

Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
 drivers/net/null/rte_eth_null.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 5895065..4ca7f09 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -298,7 +298,8 @@ 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));
 	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
-					internal->nb_rx_queues);
+			RTE_MIN(internal->nb_rx_queues,
+				RTE_DIM(internal->rx_null_queues)));
 	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_ipackets[i] =
 			internal->rx_null_queues[i].rx_pkts.cnt;
@@ -306,7 +307,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 	}
 
 	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
-					internal->nb_tx_queues);
+			RTE_MIN(internal->nb_tx_queues,
+				RTE_DIM(internal->tx_null_queues)));
 	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_opackets[i] =
 			internal->tx_null_queues[i].tx_pkts.cnt;
@@ -331,9 +333,11 @@ eth_stats_reset(struct rte_eth_dev *dev)
 		return;
 
 	internal = dev->data->dev_private;
-	for (i = 0; i < internal->nb_rx_queues; i++)
+	for (i = 0; i < internal->nb_rx_queues &&
+			i < RTE_DIM(internal->rx_null_queues); i++)
 		internal->rx_null_queues[i].rx_pkts.cnt = 0;
-	for (i = 0; i < internal->nb_tx_queues; i++) {
+	for (i = 0; i < internal->nb_tx_queues &&
+			i < RTE_DIM(internal->tx_null_queues); i++) {
 		internal->tx_null_queues[i].tx_pkts.cnt = 0;
 		internal->tx_null_queues[i].err_pkts.cnt = 0;
 	}
-- 
2.4.1



More information about the dev mailing list