mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-27 04:18:42 +00:00
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
This commit is contained in:
1 parent
2e12c745ea
commit
946af52687
2 files changed
+6
-2
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user