From 357a40ec7c20c075c985079c8591faea1ed79c0d Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Thu, 29 Aug 2019 08:59:41 +0000 Subject: [PATCH] [COFF] Fix error handling in ResourceSectionRef Previously, the expression (Reader.readFoo()) was expanded twice, triggering asserts as one of the Error types ends up not checked (and as it was expanded twice, the method would end up called twice if it failed first). Differential Revision: https://reviews.llvm.org/D66817 llvm-svn: 370309 --- llvm/lib/Object/COFFObjectFile.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp index ceb45bc930de..b3dbf75a5c32 100644 --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -1662,9 +1662,12 @@ std::error_code BaseRelocRef::getRVA(uint32_t &Result) const { return std::error_code(); } -#define RETURN_IF_ERROR(E) \ - if (E) \ - return E; +#define RETURN_IF_ERROR(Expr) \ + do { \ + Error E = (Expr); \ + if (E) \ + return std::move(E); \ + } while (0) Expected> ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {