diff --git a/src/base/system.cpp b/src/base/system.cpp index 4d5e5bc51..79e712af8 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -1290,19 +1290,15 @@ static int parse_uint16(unsigned short *out, const char **str) int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size) { - char host[128]; - int length; - int start = 0; - int end; - int failure; const char *str = str_startswith(string, "tw-0.6+udp://"); if(!str) return 1; mem_zero(addr, sizeof(*addr)); - length = str_length(str); - end = length; + int length = str_length(str); + int start = 0; + int end = length; for(int i = 0; i < length; i++) { if(str[i] == '@') @@ -1320,14 +1316,13 @@ int net_addr_from_url(NETADDR *addr, const char *string, char *host_buf, size_t break; } } + + char host[128]; str_truncate(host, sizeof(host), str + start, end - start); if(host_buf) str_copy(host_buf, host, host_buf_size); - if((failure = net_addr_from_str(addr, host))) - return failure; - - return failure; + return net_addr_from_str(addr, host); } int net_addr_from_str(NETADDR *addr, const char *string)