Skip to content

Commit

Permalink
net/mlx5: fix build with GCC 12 and ASan
Browse files Browse the repository at this point in the history
[ upstream commit e17840756179410283ef03660578310874432f40 ]

Building with gcc 12 and ASan raises this warning:

../drivers/net/mlx5/mlx5_txpp.c: In function ‘mlx5_txpp_xstats_get_names’:
../drivers/net/mlx5/mlx5_txpp.c:1066:25: error: ‘strncpy’ specified bound
	64 equals destination size [-Werror=stringop-truncation]
 1066 |                         strncpy(xstats_names[i + n_used].name,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1067 |                                 mlx5_txpp_stat_names[i],
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~
 1068 |                                 RTE_ETH_XSTATS_NAME_SIZE);
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Prefer strlcpy for xstats.

Fixes: 3b025c0 ("net/mlx5: provide send scheduling error statistics")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Raslan Darawsheh <rasland@nvidia.com>
  • Loading branch information
david-marchand authored and bluca committed Mar 28, 2023
1 parent e3779bd commit 09d45f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 1 addition & 2 deletions drivers/net/mlx5/mlx5_stats.c
Expand Up @@ -285,10 +285,9 @@ mlx5_xstats_get_names(struct rte_eth_dev *dev,

if (n >= mlx5_xstats_n && xstats_names) {
for (i = 0; i != mlx5_xstats_n; ++i) {
strncpy(xstats_names[i].name,
strlcpy(xstats_names[i].name,
xstats_ctrl->info[i].dpdk_name,
RTE_ETH_XSTATS_NAME_SIZE);
xstats_names[i].name[RTE_ETH_XSTATS_NAME_SIZE - 1] = 0;
}
}
mlx5_xstats_n = mlx5_txpp_xstats_get_names(dev, xstats_names,
Expand Down
4 changes: 1 addition & 3 deletions drivers/net/mlx5/mlx5_txpp.c
Expand Up @@ -1222,11 +1222,9 @@ int mlx5_txpp_xstats_get_names(struct rte_eth_dev *dev __rte_unused,

if (n >= n_used + n_txpp && xstats_names) {
for (i = 0; i < n_txpp; ++i) {
strncpy(xstats_names[i + n_used].name,
strlcpy(xstats_names[i + n_used].name,
mlx5_txpp_stat_names[i],
RTE_ETH_XSTATS_NAME_SIZE);
xstats_names[i + n_used].name
[RTE_ETH_XSTATS_NAME_SIZE - 1] = 0;
}
}
return n_used + n_txpp;
Expand Down

0 comments on commit 09d45f6

Please sign in to comment.