]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: net_ip2addr() - Optimize by allocating destination memory immediately
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 3 Nov 2017 23:42:37 +0000 (01:42 +0200)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 6 Nov 2017 07:34:31 +0000 (09:34 +0200)
It doesn't really matter if we allocate a few extra bytes.

src/lib/net.c

index 7dd0c120582b9bb1c19e350069a00f19f173a5fd..1e7763d748a7bb814574db0240da2a9d22834f66 100644 (file)
@@ -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)