summaryrefslogtreecommitdiffstats
path: root/llvm/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
commit743dd2cd80516104a774a03f3acdfd406d5643e3 (patch)
tree6c3f222a5555659a10cbc547fa5019f997bcc39b /llvm/lib/System/Unix/Unix.h
parente14babd14106060a5d11d7401391d04f3c52fcef (diff)
downloadbcm5719-llvm-743dd2cd80516104a774a03f3acdfd406d5643e3.tar.gz
bcm5719-llvm-743dd2cd80516104a774a03f3acdfd406d5643e3.zip
If errno is zero strerror_r does not modify the buffer, leaving it unterminated.
This causes garbage to be printed out after error messages. llvm-svn: 20165
Diffstat (limited to 'llvm/lib/System/Unix/Unix.h')
-rw-r--r--llvm/lib/System/Unix/Unix.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/System/Unix/Unix.h b/llvm/lib/System/Unix/Unix.h
index 6dc75545b66..75009d0746e 100644
--- a/llvm/lib/System/Unix/Unix.h
+++ b/llvm/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
OpenPOWER on IntegriCloud