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.2.34~251 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fade87f219286296456e1b2cecd34b0575e9439b;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 cd414113df..2facbd97d7 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -931,13 +931,12 @@ int net_getunixcred(int fd, struct net_unix_cred *cred_r) const char *net_ip2addr(const struct ip_addr *ip) { #ifdef HAVE_IPV6 - char addr[MAX_IP_LEN+1]; + char *addr = t_malloc(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; #else unsigned long ip4;