From a432943d191a9e5b2ae7c96e49261a411db978e5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 28 Feb 2019 19:58:24 +0000 Subject: [PATCH] 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. --- windows/winnet.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/windows/winnet.c b/windows/winnet.c index ba3e11bd..a9680795 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -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,