fix snprintf truncation warnings

gcc7.1 adds truncation warning, netdev_ifconf.c fix snprintf truncation warnings

Signed-off-by: zhangjun21 <zhangjun21@xiaomi.com>
This commit is contained in:
zhangjun21 2024-03-18 17:04:43 +08:00 committed by Xiang Xiao
parent c32c8da761
commit 16124b0926

View file

@ -177,6 +177,7 @@ static int ifconf_ipv6_addr_callback(FAR struct net_driver_s *dev,
(FAR struct sockaddr_in6 *)&req->lifr_addr;
#ifdef CONFIG_NETDEV_MULTIPLE_IPv6
int addr_idx = addr - dev->d_ipv6;
char ifname[IFNAMSIZ + 16];
/* There is space for information about another adapter. Within
* each ifreq structure, lifr_name will receive the interface
@ -188,12 +189,14 @@ static int ifconf_ipv6_addr_callback(FAR struct net_driver_s *dev,
{
/* eth0:0 represents the second addr on eth0 */
if (snprintf(req->lifr_name, IFNAMSIZ,
if (snprintf(ifname, sizeof(ifname),
"%s:%d", dev->d_ifname, addr_idx - 1) >= IFNAMSIZ)
{
nwarn("WARNING: ifname too long to print %s:%d\n",
dev->d_ifname, addr_idx - 1);
}
strlcpy(req->lifr_name, ifname, IFNAMSIZ);
}
else
#endif