mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-23 14:03:14 +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. llvm-svn: 20165
This commit is contained in:
parent
b84d6c75a0
commit
535796ff26
@ -51,6 +51,7 @@ void MappedFile::initialize() {
|
|||||||
else if (options_&WRITE_ACCESS)
|
else if (options_&WRITE_ACCESS)
|
||||||
mode = O_WRONLY;
|
mode = O_WRONLY;
|
||||||
info_->fd_ = ::open(path_.c_str(),mode);
|
info_->fd_ = ::open(path_.c_str(),mode);
|
||||||
|
|
||||||
if (info_->fd_ < 0) {
|
if (info_->fd_ < 0) {
|
||||||
delete info_;
|
delete info_;
|
||||||
info_ = 0;
|
info_ = 0;
|
||||||
|
@ -68,14 +68,17 @@
|
|||||||
|
|
||||||
inline void ThrowErrno(const std::string& prefix) {
|
inline void ThrowErrno(const std::string& prefix) {
|
||||||
char buffer[MAXPATHLEN];
|
char buffer[MAXPATHLEN];
|
||||||
|
buffer[0] = 0;
|
||||||
#ifdef HAVE_STRERROR_R
|
#ifdef HAVE_STRERROR_R
|
||||||
// strerror_r is thread-safe.
|
// strerror_r is thread-safe.
|
||||||
strerror_r(errno,buffer,MAXPATHLEN-1);
|
if (errno)
|
||||||
|
strerror_r(errno,buffer,MAXPATHLEN-1);
|
||||||
#elif HAVE_STRERROR
|
#elif HAVE_STRERROR
|
||||||
// Copy the thread un-safe result of strerror into
|
// Copy the thread un-safe result of strerror into
|
||||||
// the buffer as fast as possible to minimize impact
|
// the buffer as fast as possible to minimize impact
|
||||||
// of collision of strerror in multiple threads.
|
// 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;
|
buffer[MAXPATHLEN-1] = 0;
|
||||||
#else
|
#else
|
||||||
// Strange that this system doesn't even have strerror
|
// Strange that this system doesn't even have strerror
|
||||||
|
Loading…
x
Reference in New Issue
Block a user