From: Timo Sirainen Date: Fri, 3 Nov 2017 23:42:37 +0000 (+0200) Subject: lib: net_ip2addr() - Optimize by allocating destination memory immediately X-Git-Tag: 2.3.0.rc1~577 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8e9616d70b68aab3b95f89410ba6e8872c5039e8;p=thirdparty%2Fdovecot%2Fcore.git lib: net_ip2addr() - Optimize by allocating destination memory immediately It doesn't really matter if we allocate a few extra bytes. --- diff --git a/src/lib/net.c b/src/lib/net.c index 7dd0c12058..1e7763d748 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -884,13 +884,12 @@ int net_getunixcred(int fd, struct net_unix_cred *cred_r) const char *net_ip2addr(const struct ip_addr *ip) { - char addr[MAX_IP_LEN+1]; + char *addr = t_malloc_no0(MAX_IP_LEN+1); - addr[MAX_IP_LEN] = '\0'; if (inet_ntop(ip->family, &ip->u.ip6, addr, MAX_IP_LEN) == NULL) return ""; - return t_strdup(addr); + return addr; } int net_addr2ip(const char *addr, struct ip_addr *ip)