From a931b9eaf1486eedccbcd953450664b097676311 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Tue, 18 Dec 2018 17:10:39 +0200 Subject: [PATCH] HOST_NAME_MAX and LOGIN_NAME_MAX availability is not consistent across linux/android/macos platforms. However all of them do have versions of these macros with _POSIX_ prefix. In addition to that hostname and user variables may be uninitialized in some configurations, however they are always used. Initializing these arrays fixes conditional depending on uninitialized memory warning uncovered by valgrind. --- client/TracyProfiler.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 59e603c2..cccb99bd 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -289,17 +289,10 @@ static const char* GetHostInfo() ptr += sprintf( ptr, "User: %s@%s\n", user, hostname ); #else -# ifndef HOST_NAME_MAX - const size_t HOST_NAME_MAX = 1024u; -# endif -# ifndef LOGIN_NAME_MAX - const size_t LOGIN_NAME_MAX = 1024u; -# endif + char hostname[_POSIX_HOST_NAME_MAX]{}; + char user[_POSIX_LOGIN_NAME_MAX]{}; - char hostname[HOST_NAME_MAX]; - char user[LOGIN_NAME_MAX]; - - gethostname( hostname, HOST_NAME_MAX ); + gethostname( hostname, _POSIX_HOST_NAME_MAX ); # if defined __ANDROID__ const auto login = getlogin(); if( login ) @@ -311,7 +304,7 @@ static const char* GetHostInfo() memcpy( user, "(?)", 4 ); } # else - getlogin_r( user, LOGIN_NAME_MAX ); + getlogin_r( user, _POSIX_LOGIN_NAME_MAX ); # endif ptr += sprintf( ptr, "User: %s@%s\n", user, hostname );