diff options
Diffstat (limited to 'llvm/lib/System/Unix')
| -rw-r--r-- | llvm/lib/System/Unix/Path.cpp | 10 | 
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/System/Unix/Path.cpp b/llvm/lib/System/Unix/Path.cpp index 70cc4f01032..5d2a4b688c4 100644 --- a/llvm/lib/System/Unix/Path.cpp +++ b/llvm/lib/System/Unix/Path.cpp @@ -178,11 +178,13 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const {    int fd = ::open(path.c_str(),O_RDONLY);    if (fd < 0)      return false; -  if (0 != ::read(fd, buf, len)) +  ssize_t bytes_read = ::read(fd, buf, len); +  ::close(fd); +  if (ssize_t(len) != bytes_read) { +    Magic.clear();      return false; -  close(fd); -  buf[len] = '\0'; -  Magic = buf; +  } +  Magic.assign(buf,len);    return true;  }  | 

