From 835dc82e6fd1a4208bbc1b43c463d58d51810470 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Mon, 12 Mar 2018 11:25:47 +0000 Subject: [PATCH] freed from malloc and free FossilOrigin-Name: f7310807426396321ac7af203206bfe465a547182ef0f8ab74d4c2272782fa1d --- src/cw/sock_strtoaddr.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/cw/sock_strtoaddr.c b/src/cw/sock_strtoaddr.c index fe6ed808..fcd7628f 100644 --- a/src/cw/sock_strtoaddr.c +++ b/src/cw/sock_strtoaddr.c @@ -8,25 +8,25 @@ #include "sock.h" /** - * Convert a string to an sockaddr struct. + * Convert a string to a sockaddr struct. * The string can contain an ipv4 or ipv6 address, including a port number. - * @param s address string + * @param s address string, the address string MUST not be longer + * than 128 characters * @param saout output buffer - * @return 1 on success, otherwise no success + * @return 1 on success, otherwise no success, consult errno! */ int sock_strtoaddr(const char * s,struct sockaddr * saout){ - char *ips,*ps; + char ips[128],*ps; struct in_addr ia; int port; -#ifdef WITH_IPV6 +#ifndef WITHOUT_IPV6 struct in6_addr ia6; #endif int rc; /* copy the string */ - ips = malloc(strlen(s)+1); strcpy(ips,s); /* search for a collon to separate the port */ @@ -62,10 +62,9 @@ int sock_strtoaddr(const char * s,struct sockaddr * saout){ sa->sin_family = AF_INET; sa->sin_addr=ia; sa->sin_port=htons(port); - } -#ifdef WITH_IPV6 +#ifndef WITHOUT_IPV6 if (rc==0){ strcpy(ips,s); @@ -99,12 +98,12 @@ int sock_strtoaddr(const char * s,struct sockaddr * saout){ } #endif + if (rc!=1){ if (rc!=-1) errno=EINVAL; } - free (ips); return rc; }