From 7010f49fd15b978852c515d4fbf4f929b727e545 Mon Sep 17 00:00:00 2001 From: Alistair Buxton Date: Sun, 9 Nov 2014 19:28:37 +0000 Subject: [PATCH] Go back to MAX_HOSTNAME_LENGTH Platform specific values for MAX_HOSTNAME_LENGTH could be generated via autoconf tests, which should be more reliable and able to deal with more different platforms than just using HOST_NAME_MAX directly. Therefore, instead of using HOST_NAME_MAX, just increase the default for MAX_HOSTNAME_LENGTH to 256 so that it is unambiguously enough for all known (to me) platforms. namelen is MAX_HOSTNAME_LENGTH+1 so that MAX_HOSTNAME_LENGTH can safely be redefined to the value of HOST_NAME_MAX (or other platform specifics), which may or may not include the null terminator. The buffer is length MAX_HOSTNAME_LENGTH+2 because it must be one byte larger than namelen to ensure it is always null terminated if the default value is used (ie if we don't know the real platform limit.) The null check and the warning from the previous commit are kept. For more information see: https://bugzilla.xfce.org/show_bug.cgi?id=11282 https://bugzilla.xfce.org/show_bug.cgi?id=11289 --- src/display.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/display.c b/src/display.c index 3c2e7ba..669a07c 100644 --- a/src/display.c +++ b/src/display.c @@ -44,9 +44,9 @@ #include "client.h" #include "compositor.h" -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 255 -#endif /* HOST_NAME_MAX */ +#ifndef MAX_HOSTNAME_LENGTH +#define MAX_HOSTNAME_LENGTH 256 +#endif /* MAX_HOSTNAME_LENGTH */ #ifndef CURSOR_ROOT #define CURSOR_ROOT XC_left_ptr @@ -313,8 +313,8 @@ myDisplayInit (GdkDisplay *gdisplay) display->nb_screens = 0; display->current_time = CurrentTime; - display->hostname = g_new0 (gchar, (size_t) HOST_NAME_MAX + 1); - if (gethostname ((char *) display->hostname, HOST_NAME_MAX + 1)) + display->hostname = g_new0 (gchar, (size_t) MAX_HOSTNAME_LENGTH + 2); + if (gethostname ((char *) display->hostname, MAX_HOSTNAME_LENGTH + 1)) { g_warning ("The display's hostname could not be determined."); g_free (display->hostname); -- 1.9.1