Minor refactoring of net_addr_from_url

- Remove unnecessary branch and temporary variable usage at the end of the function.
- Move variable declarations closer to usages.
This commit is contained in:
Robert Müller 2024-03-15 18:40:03 +01:00
parent 6df1d251d7
commit 24caf08d84

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)