]> granicus.if.org Git - clang/commitdiff
Update r228592 for when gethostname() returns an error
authorBen Langmuir <blangmuir@apple.com>
Mon, 9 Feb 2015 20:13:11 +0000 (20:13 +0000)
committerBen Langmuir <blangmuir@apple.com>
Mon, 9 Feb 2015 20:13:11 +0000 (20:13 +0000)
If gethostname() is not successful, just skip adding the hostname to the
module hash.  And don't bother setting hostname[255] = 0, since if
gethostname() is successful, it will be null-terminated already (and if
it's not successful we don't read the string now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228601 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/CompilerInvocation.cpp

index ac3c31180446ecb07994f2cc1c0217fd114cb451..e1d9351aa38da20f149b6706198b1ade44f9f9ff 100644 (file)
@@ -2028,10 +2028,10 @@ std::string CompilerInvocation::getModuleHash() const {
   // The LockFileManager cannot tell when processes from another host are
   // running, so mangle the hostname in to the module hash to separate them.
   char hostname[256];
-  hostname[255] = 0;
   hostname[0] = 0;
-  gethostname(hostname, 255);
-  code = hash_combine(code, StringRef(hostname));
+  if (gethostname(hostname, 255) == 0)
+    code = hash_combine(code, StringRef(hostname));
+  // Ignore failures in gethostname() by not including the hostname in the hash.
 #endif
 
   return llvm::APInt(64, code).toString(36, /*Signed=*/false);