MemoryBuffer: Add a missing error-check to getOpenFileImpl

Summary:
In case the function was called with a desired read size *and* the file
was not an "mmap()" candidate, the function was falling back to a
"pread()", but it was failing to check the result of that system call.
This meant that the function would return "success" even though the read
operation failed, and it returned a buffer full of uninitialized memory.

Reviewers: rnk, dblaikie

Subscribers: kristina, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66224

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368977 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pavel Labath
2019-08-15 08:20:15 +00:00
parent f7118a429a
commit 4cf866ce04
2 changed files with 54 additions and 1 deletions
+3 -1
View File
@@ -458,7 +458,9 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
return make_error_code(errc::not_enough_memory);
}
sys::fs::readNativeFileSlice(FD, Buf->getBuffer(), Offset);
if (std::error_code EC =
sys::fs::readNativeFileSlice(FD, Buf->getBuffer(), Offset))
return EC;
return std::move(Buf);
}