[llvm] a9e2984 - [llvm-pdbutil] Fix a crash due to Expected not checked before destruction

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 10:01:44 PDT 2022


Author: Zequan Wu
Date: 2022-03-29T10:01:32-07:00
New Revision: a9e29848a2b441eca687495c8fe462340c1407d1

URL: https://github.com/llvm/llvm-project/commit/a9e29848a2b441eca687495c8fe462340c1407d1
DIFF: https://github.com/llvm/llvm-project/commit/a9e29848a2b441eca687495c8fe462340c1407d1.diff

LOG: [llvm-pdbutil] Fix a crash due to Expected not checked before destruction

Reviewed By: aganea

Differential Revision: https://reviews.llvm.org/D122622

Added: 
    

Modified: 
    llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
index c3d95c836aa73..2bcdab14c4d71 100644
--- a/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
+++ b/llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
@@ -412,10 +412,10 @@ loadSectionHeaders(PDBFile &File, DbgHeaderType Type) {
   return std::make_pair(std::move(Stream), Headers);
 }
 
-static std::vector<std::string> getSectionNames(PDBFile &File) {
+static Expected<std::vector<std::string>> getSectionNames(PDBFile &File) {
   auto ExpectedHeaders = loadSectionHeaders(File, DbgHeaderType::SectionHdr);
   if (!ExpectedHeaders)
-    return {};
+    return ExpectedHeaders.takeError();
 
   std::unique_ptr<MappedBlockStream> Stream;
   ArrayRef<object::coff_section> Headers;
@@ -485,7 +485,10 @@ Error DumpOutputStyle::dumpModules() {
       [&](uint32_t Modi, const SymbolGroup &Strings) -> Error {
         auto Desc = Modules.getModuleDescriptor(Modi);
         if (opts::dump::DumpSectionContribs) {
-          std::vector<std::string> Sections = getSectionNames(getPdb());
+          auto SectionsOrErr = getSectionNames(getPdb());
+          if (!SectionsOrErr)
+            return SectionsOrErr.takeError();
+          ArrayRef<std::string> Sections = *SectionsOrErr;
           dumpSectionContrib(P, Desc.getSectionContrib(), Sections, 0);
         }
         P.formatLine("Obj: `{0}`: ", Desc.getObjFileName());
@@ -1840,8 +1843,11 @@ Error DumpOutputStyle::dumpSectionContribs() {
     ArrayRef<std::string> Names;
   };
 
-  std::vector<std::string> Names = getSectionNames(getPdb());
-  Visitor V(P, makeArrayRef(Names));
+  auto NamesOrErr = getSectionNames(getPdb());
+  if (!NamesOrErr)
+    return NamesOrErr.takeError();
+  ArrayRef<std::string> Names = *NamesOrErr;
+  Visitor V(P, Names);
   Dbi.visitSectionContributions(V);
   return Error::success();
 }


        


More information about the llvm-commits mailing list