[PATCH] D66817: [03/10] [COFF] Fix error handling in ResourceSectionRef

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 12:04:12 PDT 2019


mstorsjo created this revision.
mstorsjo added reviewers: thakis, rnk, ruiu.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

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).

Do we need a test with an intentionally broken object file to test this?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66817

Files:
  llvm/lib/Object/COFFObjectFile.cpp


Index: llvm/lib/Object/COFFObjectFile.cpp
===================================================================
--- llvm/lib/Object/COFFObjectFile.cpp
+++ llvm/lib/Object/COFFObjectFile.cpp
@@ -1662,9 +1662,12 @@
   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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66817.217464.patch
Type: text/x-patch
Size: 939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190827/465d1cac/attachment.bin>


More information about the llvm-commits mailing list