]> granicus.if.org Git - llvm/commitdiff
Fix a null pointer dereference in llvm-pdbutil pretty.
authorZachary Turner <zturner@google.com>
Mon, 12 Jun 2017 20:46:35 +0000 (20:46 +0000)
committerZachary Turner <zturner@google.com>
Mon, 12 Jun 2017 20:46:35 +0000 (20:46 +0000)
Static data members were causing a problem because I mistakenly
assumed all members would affect a class's layout and so the
Layout member would be non-null.

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

lib/DebugInfo/PDB/UDTLayout.cpp
tools/llvm-pdbutil/PrettyClassLayoutGraphicalDumper.cpp

index aacefae80c3a28dcd2243fd9cdf2069e903bbc2c..da353cb6977ce779ddda632838c12d817a5124e2 100644 (file)
@@ -181,13 +181,14 @@ void UDTLayoutBase::initializeChildren(const PDBSymbol &Sym) {
       if (Data->getDataKind() == PDB_DataKind::Member)
         Members.push_back(std::move(Data));
       else
-        Other.push_back(std::move(Child));
+        Other.push_back(std::move(Data));
     } else if (auto VT = unique_dyn_cast<PDBSymbolTypeVTable>(Child))
       VTables.push_back(std::move(VT));
     else if (auto Func = unique_dyn_cast<PDBSymbolFunc>(Child))
       Funcs.push_back(std::move(Func));
-    else
+    else {
       Other.push_back(std::move(Child));
+    }
   }
 
   // We don't want to have any re-allocations in the list of bases, so make
index 54e33683f5526ef73b1cf374f2ec9240e622c104..66c29fc5d4eece095369e84ffe93e943ad51933d 100644 (file)
@@ -151,21 +151,21 @@ bool PrettyClassLayoutGraphicalDumper::shouldRecurse() const {
 }
 
 void PrettyClassLayoutGraphicalDumper::dump(const PDBSymbolData &Symbol) {
-  assert(CurrentItem != nullptr);
-
-  DataMemberLayoutItem &Layout =
-      static_cast<DataMemberLayoutItem &>(*CurrentItem);
-
   VariableDumper VarDumper(Printer);
   VarDumper.start(Symbol, ClassOffsetZero);
 
-  if (Layout.hasUDTLayout() && shouldRecurse()) {
-    uint32_t ChildOffsetZero = ClassOffsetZero + Layout.getOffsetInParent();
-    Printer.Indent();
-    PrettyClassLayoutGraphicalDumper TypeDumper(Printer, RecursionLevel + 1,
-                                                ChildOffsetZero);
-    TypeDumper.start(Layout.getUDTLayout());
-    Printer.Unindent();
+  if (CurrentItem != nullptr) {
+    DataMemberLayoutItem &Layout =
+        static_cast<DataMemberLayoutItem &>(*CurrentItem);
+
+    if (Layout.hasUDTLayout() && shouldRecurse()) {
+      uint32_t ChildOffsetZero = ClassOffsetZero + Layout.getOffsetInParent();
+      Printer.Indent();
+      PrettyClassLayoutGraphicalDumper TypeDumper(Printer, RecursionLevel + 1,
+                                                  ChildOffsetZero);
+      TypeDumper.start(Layout.getUDTLayout());
+      Printer.Unindent();
+    }
   }
 
   DumpedAnything = true;