diff options
author | Ben Langmuir <blangmuir@apple.com> | 2015-02-09 21:55:44 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2015-02-09 21:55:44 +0000 |
commit | 541c202be860af8564766bcd787f105002e3dde4 (patch) | |
tree | 991fc5630468d26016aada93c20198e29ddada6d /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 5fc82fd6b5af5ae9d2f43ee847213ba2fbeda45f (diff) | |
download | llvm-541c202be860af8564766bcd787f105002e3dde4.zip llvm-541c202be860af8564766bcd787f105002e3dde4.tar.gz llvm-541c202be860af8564766bcd787f105002e3dde4.tar.bz2 |
Be more conservative about gethostname()'s truncating behaviour
Don't assume it will provide an error or null-terminate the string on
truncation, since POSIX doesn't guarantee either behaviour (although
Linux and Darwin at least will do the 'right thing').
llvm-svn: 228613
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index e1d9351a..c1ad805 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2029,8 +2029,12 @@ std::string CompilerInvocation::getModuleHash() const { // running, so mangle the hostname in to the module hash to separate them. char hostname[256]; hostname[0] = 0; - if (gethostname(hostname, 255) == 0) + if (gethostname(hostname, 255) == 0) { + // Forcibly null-terminate the result, since POSIX doesn't require that + // truncation result in an error or that truncated names be null-terminated. + hostname[sizeof(hostname)-1] = 0; code = hash_combine(code, StringRef(hostname)); + } // Ignore failures in gethostname() by not including the hostname in the hash. #endif |