OSDN Git Service

Don't dereference a symbol iterator before checking for the end case
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 29 May 2016 06:18:08 +0000 (06:18 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 29 May 2016 06:18:08 +0000 (06:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271173 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-readobj/COFFDumper.cpp

index 029674b..bf6a7b4 100644 (file)
@@ -208,15 +208,19 @@ std::error_code COFFDumper::resolveSymbol(const coff_section *Section,
                                           uint64_t Offset, SymbolRef &Sym) {
   cacheRelocations();
   const auto &Relocations = RelocMap[Section];
+  auto SymI = Obj->symbol_end();
   for (const auto &Relocation : Relocations) {
     uint64_t RelocationOffset = Relocation.getOffset();
 
     if (RelocationOffset == Offset) {
-      Sym = *Relocation.getSymbol();
-      return readobj_error::success;
+      SymI = Relocation.getSymbol();
+      break;
     }
   }
-  return readobj_error::unknown_symbol;
+  if (SymI == Obj->symbol_end())
+    return readobj_error::unknown_symbol;
+  Sym = *SymI;
+  return readobj_error::success;
 }
 
 // Given a section and an offset into this section the function returns the name