diff options
author | Peter Bloomfield <PeterBloomfield@bellsouth.net> | 2020-09-22 16:14:21 -0400 |
---|---|---|
committer | Peter Bloomfield <PeterBloomfield@bellsouth.net> | 2020-09-22 16:14:21 -0400 |
commit | e64293d56c35db4ab8f787d809cafed200f11235 (patch) | |
tree | 9bc281467abf3cc06ae565d820ea7e7a826930b5 | |
parent | 298b712b2726624c9d806dcb949446d895adab87 (diff) | |
download | glib-e64293d56c35db4ab8f787d809cafed200f11235.tar.gz |
utils: Limit the scope of the variable `max`
in g_get_host_name(), and avoid an unused-variable warning when
_SC_HOST_NAME_MAX is not defined.
-rw-r--r-- | glib/gutils.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/glib/gutils.c b/glib/gutils.c index aff3ed442..15c0c0037 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -982,7 +982,6 @@ g_get_host_name (void) gchar *utmp; #ifndef G_OS_WIN32 - glong max; gsize size; /* The number 256 * 256 is taken from the value of _POSIX_HOST_NAME_MAX, * which is 255. Since we use _POSIX_HOST_NAME_MAX + 1 (= 256) in the @@ -994,15 +993,19 @@ g_get_host_name (void) gchar *tmp; #ifdef _SC_HOST_NAME_MAX - max = sysconf (_SC_HOST_NAME_MAX); - if (max > 0 && (gsize) max <= G_MAXSIZE - 1) - size = (gsize) max + 1; - else + { + glong max; + + max = sysconf (_SC_HOST_NAME_MAX); + if (max > 0 && (gsize) max <= G_MAXSIZE - 1) + size = (gsize) max + 1; + else #ifdef HOST_NAME_MAX - size = HOST_NAME_MAX + 1; + size = HOST_NAME_MAX + 1; #else - size = _POSIX_HOST_NAME_MAX + 1; + size = _POSIX_HOST_NAME_MAX + 1; #endif /* HOST_NAME_MAX */ + } #else /* Fallback to some reasonable value */ size = 256; |