The compiler doesn't know that all the elements in the table of queue stats are short enough to avoid overflowing the snprintf. Add a condition that will not happen to warn if it ever does; maybe some day a new long named queue stat could be added.
Signed-off-by: Stephen Hemminger <[email protected]> --- lib/ethdev/rte_ethdev.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index c6fe0d5165..5bd3fbc0bc 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -3501,10 +3501,16 @@ eth_basic_stats_get_names(struct rte_eth_dev *dev, num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); for (id_queue = 0; id_queue < num_q; id_queue++) { for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) { - snprintf(xstats_names[cnt_used_entries].name, - sizeof(xstats_names[0].name), - "rx_q%u_%s", - id_queue, eth_dev_rxq_stats_strings[idx].name); + unsigned int cc; + + cc = snprintf(xstats_names[cnt_used_entries].name, sizeof(xstats_names[0].name), + "rx_q%u_%s", + id_queue, eth_dev_rxq_stats_strings[idx].name); + + /* could only happen if a long string was added to eth_dev_rxq_stats_strings */ + if (cc >= sizeof(xstats_names[0].name)) + RTE_ETHDEV_LOG_LINE(ERR, "truncated rxq stat string '%s'", + eth_dev_rxq_stats_strings[idx].name); cnt_used_entries++; } @@ -3512,10 +3518,15 @@ eth_basic_stats_get_names(struct rte_eth_dev *dev, num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); for (id_queue = 0; id_queue < num_q; id_queue++) { for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) { - snprintf(xstats_names[cnt_used_entries].name, - sizeof(xstats_names[0].name), - "tx_q%u_%s", - id_queue, eth_dev_txq_stats_strings[idx].name); + unsigned int cc; + + cc = snprintf(xstats_names[cnt_used_entries].name, sizeof(xstats_names[0].name), + "tx_q%u_%s", + id_queue, eth_dev_txq_stats_strings[idx].name); + /* could only happen if a long string was added to eth_dev_rxq_stats_strings */ + if (cc >= sizeof(xstats_names[0].name)) + RTE_ETHDEV_LOG_LINE(ERR, "truncated txq stat string '%s'", + eth_dev_txq_stats_strings[idx].name); cnt_used_entries++; } } -- 2.51.0

