summaryrefslogtreecommitdiff
path: root/lib/System/Unix/Unix.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-02-13 22:46:37 +0000
committerChris Lattner <sabre@nondot.org>2005-02-13 22:46:37 +0000
commit946af52687fea113a6596385bfbdb26994709a37 (patch)
treebd1830b39bcb205b95f317f0fb1f7c21cc173051 /lib/System/Unix/Unix.h
parent2e12c745eae4be1f0c5c5f4840c58918c11c6b1d (diff)
downloadllvm-946af52687fea113a6596385bfbdb26994709a37.tar.gz
llvm-946af52687fea113a6596385bfbdb26994709a37.tar.bz2
llvm-946af52687fea113a6596385bfbdb26994709a37.tar.xz
If errno is zero strerror_r does not modify the buffer, leaving it unterminated.
This causes garbage to be printed out after error messages. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20165 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix/Unix.h')
-rw-r--r--lib/System/Unix/Unix.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/System/Unix/Unix.h b/lib/System/Unix/Unix.h
index 6dc75545b6..75009d0746 100644
--- a/lib/System/Unix/Unix.h
+++ b/lib/System/Unix/Unix.h
@@ -68,14 +68,17 @@
inline void ThrowErrno(const std::string& prefix) {
char buffer[MAXPATHLEN];
+ buffer[0] = 0;
#ifdef HAVE_STRERROR_R
// strerror_r is thread-safe.
- strerror_r(errno,buffer,MAXPATHLEN-1);
+ if (errno)
+ strerror_r(errno,buffer,MAXPATHLEN-1);
#elif HAVE_STRERROR
// Copy the thread un-safe result of strerror into
// the buffer as fast as possible to minimize impact
// of collision of strerror in multiple threads.
- strncpy(buffer,strerror(errno),MAXPATHLEN-1);
+ if (Errno)
+ strncpy(buffer,strerror(errno),MAXPATHLEN-1);
buffer[MAXPATHLEN-1] = 0;
#else
// Strange that this system doesn't even have strerror