1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Remove reallocation loop in Windows get_hostname.

I've just noticed that the MSDN docs for WinSock gethostname()
guarantee that a size-256 buffer is large enough. That seems a lot
simpler than the previous faff.
This commit is contained in:
Simon Tatham 2019-02-28 19:58:24 +00:00
parent 59c8df4130
commit a432943d19

View File

@ -1816,18 +1816,10 @@ int net_service_lookup(char *service)
char *get_hostname(void)
{
int len = 128;
char *hostname = NULL;
do {
len *= 2;
hostname = sresize(hostname, len, char);
if (p_gethostname(hostname, len) < 0) {
sfree(hostname);
hostname = NULL;
break;
}
} while (strlen(hostname) >= (size_t)(len-1));
return hostname;
char hostbuf[256]; /* MSDN docs for gethostname() promise this is enough */
if (p_gethostname(hostbuf, sizeof(hostbuf)) < 0)
return NULL;
return dupstr(hostbuf);
}
SockAddr *platform_get_x11_unix_address(const char *display, int displaynum,