From 0f7ccf0c087160ecf2337338637e4dc9997bafab Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Fri, 18 Mar 2022 22:37:12 +0800 Subject: [PATCH] netdb/getaddrinfo: fix the compile warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit netdb/lib_getaddrinfo.c: In function ‘alloc_ai’: netdb/lib_getaddrinfo.c:80:9: warning: ‘strncpy’ specified bound 108 equals destination size [-Wstringop-truncation] 80 | strncpy(ai->sa.sun.sun_path, addr, sizeof(ai->sa.sun.sun_path)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ netdb/lib_getaddrinfo.c: In function ‘alloc_ai’: netdb/lib_getaddrinfo.c:103:9: warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation] 103 | strncpy(ai->sa.srp.rp_cpu, addr, sizeof(ai->sa.srp.rp_cpu)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: chao.an --- libs/libc/netdb/lib_getaddrinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/libc/netdb/lib_getaddrinfo.c b/libs/libc/netdb/lib_getaddrinfo.c index f819ca4c12..bb14ef3967 100644 --- a/libs/libc/netdb/lib_getaddrinfo.c +++ b/libs/libc/netdb/lib_getaddrinfo.c @@ -77,7 +77,7 @@ FAR static struct ai_s *alloc_ai(int family, int socktype, int protocol, case AF_LOCAL: ai->ai.ai_addrlen = sizeof(struct sockaddr_un); ai->sa.sun.sun_family = AF_LOCAL; - strncpy(ai->sa.sun.sun_path, addr, sizeof(ai->sa.sun.sun_path)); + strlcpy(ai->sa.sun.sun_path, addr, sizeof(ai->sa.sun.sun_path)); break; #endif #ifdef CONFIG_NET_IPv4 @@ -100,7 +100,7 @@ FAR static struct ai_s *alloc_ai(int family, int socktype, int protocol, case AF_RPMSG: ai->ai.ai_addrlen = sizeof(struct sockaddr_rpmsg); ai->sa.srp.rp_family = AF_RPMSG; - strncpy(ai->sa.srp.rp_cpu, addr, sizeof(ai->sa.srp.rp_cpu)); + strlcpy(ai->sa.srp.rp_cpu, addr, sizeof(ai->sa.srp.rp_cpu)); snprintf(ai->sa.srp.rp_name, sizeof(ai->sa.srp.rp_name), "%d", port); break; #endif