Merge pull request #8105 from Robyt3/Base-net_addr_from_url-Refactor

Minor refactoring of `net_addr_from_url`
This commit is contained in:
archimede67 2024-03-15 20:48:56 +00:00 committed by GitHub
commit bcfc61b82a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)