comparison src/lib/net.c @ 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 22c5f005625a
children da6cf4b7caf4
comparison
equal deleted inserted replaced
22637:da955f909fdd 22638:7d5634889da8
929 } 929 }
930 930
931 const char *net_ip2addr(const struct ip_addr *ip) 931 const char *net_ip2addr(const struct ip_addr *ip)
932 { 932 {
933 #ifdef HAVE_IPV6 933 #ifdef HAVE_IPV6
934 char addr[MAX_IP_LEN+1]; 934 char *addr = t_malloc(MAX_IP_LEN+1);
935 935
936 addr[MAX_IP_LEN] = '\0';
937 if (inet_ntop(ip->family, &ip->u.ip6, addr, MAX_IP_LEN) == NULL) 936 if (inet_ntop(ip->family, &ip->u.ip6, addr, MAX_IP_LEN) == NULL)
938 return ""; 937 return "";
939 938
940 return t_strdup(addr); 939 return addr;
941 #else 940 #else
942 unsigned long ip4; 941 unsigned long ip4;
943 942
944 if (ip->family != AF_INET) 943 if (ip->family != AF_INET)
945 return ""; 944 return "";