This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 16124b0926 fix snprintf truncation warnings
16124b0926 is described below

commit 16124b0926a9f0a742222f113bab66d1d10341cf
Author: zhangjun21 <[email protected]>
AuthorDate: Mon Mar 18 17:04:43 2024 +0800

    fix snprintf truncation warnings
    
    gcc7.1 adds truncation warning, netdev_ifconf.c fix snprintf truncation 
warnings
    
    Signed-off-by: zhangjun21 <[email protected]>
---
 net/netdev/netdev_ifconf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/netdev/netdev_ifconf.c b/net/netdev/netdev_ifconf.c
index 282df17b32..024254f20b 100644
--- a/net/netdev/netdev_ifconf.c
+++ b/net/netdev/netdev_ifconf.c
@@ -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

Reply via email to