]> granicus.if.org Git - llvm/commitdiff
[COFF] Fix error handling in ResourceSectionRef
authorMartin Storsjo <martin@martin.st>
Thu, 29 Aug 2019 08:59:41 +0000 (08:59 +0000)
committerMartin Storsjo <martin@martin.st>
Thu, 29 Aug 2019 08:59:41 +0000 (08:59 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370309 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/COFFObjectFile.cpp

index ceb45bc930de1ae09ec620d4614ca326dcf11eec..b3dbf75a5c32bca6460e927a99c4bd27586db6bd 100644 (file)
@@ -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<ArrayRef<UTF16>>
 ResourceSectionRef::getDirStringAtOffset(uint32_t Offset) {