From 91b35a0b6264b6fca128f66d3fe4cda03d9ccbd3 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Mon, 26 Sep 2022 11:30:40 +0800 Subject: [PATCH] os: fix Mac test error --- include/os/osSocket.h | 2 +- source/libs/sync/src/syncUtil.c | 2 +- source/os/src/osSocket.c | 8 +++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/os/osSocket.h b/include/os/osSocket.h index 4bad51e263..c6729da76a 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -167,7 +167,7 @@ uint32_t ip2uint(const char *const ip_addr); void taosIgnSIGPIPE(); void taosSetMaskSIGPIPE(); uint32_t taosInetAddr(const char *ipAddr); -const char *taosInetNtoa(struct in_addr ipInt); +const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len); #ifdef __cplusplus } diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 15e94baee4..325073f366 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -57,7 +57,7 @@ void syncUtilU642Addr(uint64_t u64, char* host, size_t len, uint16_t* port) { struct in_addr addr; addr.s_addr = hostU32; - snprintf(host, len, "%s", taosInetNtoa(addr)); + taosInetNtoa(addr, host, len); *port = (uint16_t)((u64 & 0x00000000FFFF0000) >> 16); } diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 22b91ddf1d..b34d071773 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -312,10 +312,8 @@ uint32_t taosInetAddr(const char *ipAddr) { return inet_addr(ipAddr); #endif } -const char *taosInetNtoa(struct in_addr ipInt) { - // not thread safe, only for debug usage while print log - char tmpDstStr[16]; - return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN); +const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len) { + return inet_ntop(AF_INET, &ipInt, dstStr, len); } #ifndef SIGPIPE @@ -666,7 +664,7 @@ int taosGetLocalIp(const char *eth, char *ip) { return -1; } memcpy(&sin, &ifr.ifr_addr, sizeof(sin)); - snprintf(ip, 64, "%s", taosInetNtoa(sin.sin_addr)); + taosInetNtoa(sin.sin_addr, ip, 64); taosCloseSocketNoCheck1(fd); #endif return 0; -- GitLab