Don't read one command past the end.
Thanks to Evgeniy Stepanov for reporting this.
It might be a good idea to add a command iterator abstraction to MachO.h, but
this fixes the bug for now.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179848 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp
index e4d9ce2..d78d7f3 100644
--- a/tools/llvm-objdump/MachODump.cpp
+++ b/tools/llvm-objdump/MachODump.cpp
@@ -205,7 +205,7 @@
MachOObjectFile::LoadCommandInfo Command =
MachOObj->getFirstLoadCommandInfo();
- for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
+ for (unsigned i = 0; ; ++i) {
if (Command.C.Type == macho::LCT_FunctionStarts) {
// We found a function starts segment, parse the addresses for later
// consumption.
@@ -214,7 +214,11 @@
MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
}
- Command = MachOObj->getNextLoadCommandInfo(Command);
+
+ if (i == Header.NumLoadCommands - 1)
+ break;
+ else
+ Command = MachOObj->getNextLoadCommandInfo(Command);
}
}