diff options
author | Reid Kleckner <rnk@google.com> | 2020-06-05 16:12:38 -0700 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2020-06-05 16:27:31 -0700 |
commit | e03a135be8cf912fbfeac11c28d0132b52f1fb07 (patch) | |
tree | 02c8542956d8de590defbafabb3db401f1bd892c /llvm/lib/Object/XCOFFObjectFile.cpp | |
parent | 1c44ace1e517f8c852fd2bd1d92c6443b525b2e2 (diff) | |
download | llvm-e03a135be8cf912fbfeac11c28d0132b52f1fb07.zip llvm-e03a135be8cf912fbfeac11c28d0132b52f1fb07.tar.gz llvm-e03a135be8cf912fbfeac11c28d0132b52f1fb07.tar.bz2 |
Re-land "Migrate Binary::checkOffset from error_code to Error, NFC"
This reverts commit 38f3ba591e3a64fa5bbe684b3171c7bda6c5b527.
Fix the XCOFF error handling. Unlike std::error_code, Error must be
consumed or handled.
Diffstat (limited to 'llvm/lib/Object/XCOFFObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/XCOFFObjectFile.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp index d41afc8..55d3323 100644 --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -29,8 +29,8 @@ template <typename T> static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr, const uint64_t Size = sizeof(T)) { uintptr_t Addr = uintptr_t(Ptr); - if (std::error_code EC = Binary::checkOffset(M, Addr, Size)) - return errorCodeToError(EC); + if (Error E = Binary::checkOffset(M, Addr, Size)) + return std::move(E); return reinterpret_cast<const T *>(Addr); } @@ -668,9 +668,11 @@ Expected<XCOFFStringTable> XCOFFObjectFile::parseStringTable(const XCOFFObjectFile *Obj, uint64_t Offset) { // If there is a string table, then the buffer must contain at least 4 bytes // for the string table's size. Not having a string table is not an error. - if (auto EC = Binary::checkOffset( - Obj->Data, reinterpret_cast<uintptr_t>(Obj->base() + Offset), 4)) + if (Error E = Binary::checkOffset( + Obj->Data, reinterpret_cast<uintptr_t>(Obj->base() + Offset), 4)) { + consumeError(std::move(E)); return XCOFFStringTable{0, nullptr}; + } // Read the size out of the buffer. uint32_t Size = support::endian::read32be(Obj->base() + Offset); |