[llvm-commits] CVS: llvm/lib/System/Unix/MappedFile.inc Unix.h

Chris Lattner lattner at cs.uiuc.edu
Sun Feb 13 14:46:52 PST 2005



Changes in directory llvm/lib/System/Unix:

MappedFile.inc updated: 1.9 -> 1.10
Unix.h updated: 1.10 -> 1.11
---
Log message:

If errno is zero strerror_r does not modify the buffer, leaving it unterminated.
This causes garbage to be printed out after error messages.


---
Diffs of the changes:  (+6 -2)

 MappedFile.inc |    1 +
 Unix.h         |    7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)


Index: llvm/lib/System/Unix/MappedFile.inc
diff -u llvm/lib/System/Unix/MappedFile.inc:1.9 llvm/lib/System/Unix/MappedFile.inc:1.10
--- llvm/lib/System/Unix/MappedFile.inc:1.9	Mon Dec 27 00:16:52 2004
+++ llvm/lib/System/Unix/MappedFile.inc	Sun Feb 13 16:46:37 2005
@@ -51,6 +51,7 @@
     else if (options_&WRITE_ACCESS)
       mode = O_WRONLY;
     info_->fd_ = ::open(path_.c_str(),mode);
+
     if (info_->fd_ < 0) {
       delete info_;
       info_ = 0;


Index: llvm/lib/System/Unix/Unix.h
diff -u llvm/lib/System/Unix/Unix.h:1.10 llvm/lib/System/Unix/Unix.h:1.11
--- llvm/lib/System/Unix/Unix.h:1.10	Mon Dec 27 00:17:50 2004
+++ llvm/lib/System/Unix/Unix.h	Sun Feb 13 16:46:37 2005
@@ -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






More information about the llvm-commits mailing list