changeset 22638:7d5634889da8

lib: net_ip2addr() - Optimize by allocating destination memory immediately It doesn't really matter if we allocate a few extra bytes.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sat, 04 Nov 2017 01:42:37 +0200
parents da955f909fdd
children da6cf4b7caf4
files src/lib/net.c
diffstat 1 files changed, 2 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/net.c	Sat Nov 04 01:40:24 2017 +0200
+++ b/src/lib/net.c	Sat Nov 04 01:42:37 2017 +0200
@@ -931,13 +931,12 @@
 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;