mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 18:56:10 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user