Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 2b90611

Browse files
author
Nick Kledzik
committed
[llvm-objdump] properly use c_str() with format("%s"). Improve getLibraryShortNameByIndex() error handling.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217930 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 5c16c4e commit 2b90611

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

lib/Object/MachOObjectFile.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,27 +1184,22 @@ std::error_code MachOObjectFile::getLibraryShortNameByIndex(unsigned Index,
11841184
if (Index >= Libraries.size())
11851185
return object_error::parse_failed;
11861186

1187-
MachO::dylib_command D =
1188-
getStruct<MachO::dylib_command>(this, Libraries[Index]);
1189-
if (D.dylib.name >= D.cmdsize)
1190-
return object_error::parse_failed;
1191-
11921187
// If the cache of LibrariesShortNames is not built up do that first for
11931188
// all the Libraries.
11941189
if (LibrariesShortNames.size() == 0) {
11951190
for (unsigned i = 0; i < Libraries.size(); i++) {
11961191
MachO::dylib_command D =
11971192
getStruct<MachO::dylib_command>(this, Libraries[i]);
1198-
if (D.dylib.name >= D.cmdsize) {
1199-
LibrariesShortNames.push_back(StringRef());
1200-
continue;
1201-
}
1193+
if (D.dylib.name >= D.cmdsize)
1194+
return object_error::parse_failed;
12021195
const char *P = (const char *)(Libraries[i]) + D.dylib.name;
12031196
StringRef Name = StringRef(P);
1197+
if (D.dylib.name+Name.size() >= D.cmdsize)
1198+
return object_error::parse_failed;
12041199
StringRef Suffix;
12051200
bool isFramework;
12061201
StringRef shortName = guessLibraryShortName(Name, isFramework, Suffix);
1207-
if (shortName == StringRef())
1202+
if (shortName.empty())
12081203
LibrariesShortNames.push_back(Name);
12091204
else
12101205
LibrariesShortNames.push_back(shortName);

test/tools/llvm-objdump/macho-bind.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
# CHECK:__DATA __data 0x00001028 pointer 0 flat-namespace _any
77
# CHECK:__DATA __data 0x00001020 pointer 0 main-executable _fromApp
88
# CHECK:__DATA __data 0x00001018 pointer 0 this-image _myfunc
9-
# CHECK:__DATA __data 0x00001000 pointer 0 libfoo.dylib _foo
10-
# CHECK:__DATA __data 0x00001008 pointer 0 libbar.dylib _bar
11-
# CHECK:__DATA __data 0x00001010 pointer 0 libSystem.B.dylib _malloc
9+
# CHECK:__DATA __data 0x00001000 pointer 0 libfoo _foo
10+
# CHECK:__DATA __data 0x00001008 pointer 0 libbar _bar
11+
# CHECK:__DATA __data 0x00001010 pointer 0 libSystem _malloc

test/tools/llvm-objdump/macho-lazy-bind.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# RUN: && FileCheck %s < %t || cat %t
44

55

6-
# CHECK: __DATA __la_symbol_ptr 0x100001010 libfoo.dylib _foo
7-
# CHECK: __DATA __la_symbol_ptr 0x100001018 libbar.dylib _bar
8-
# CHECK: __DATA __la_symbol_ptr 0x100001020 libSystem.B.dylib _malloc
6+
# CHECK: __DATA __la_symbol_ptr 0x100001010 libfoo _foo
7+
# CHECK: __DATA __la_symbol_ptr 0x100001018 libbar _bar
8+
# CHECK: __DATA __la_symbol_ptr 0x100001020 libSystem _malloc

tools/llvm-objdump/MachODump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ void llvm::printMachOBindTable(const object::MachOObjectFile *Obj) {
24822482
Address,
24832483
Entry.typeName().str().c_str(),
24842484
Entry.addend(),
2485-
ordinalName(Obj, Entry.ordinal()))
2485+
ordinalName(Obj, Entry.ordinal()).str().c_str())
24862486
<< Entry.symbolName();
24872487
if (Entry.flags() & MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT)
24882488
outs() << " (weak_import)\n";
@@ -2514,7 +2514,7 @@ void llvm::printMachOLazyBindTable(const object::MachOObjectFile *Obj) {
25142514
SegmentName.str().c_str(),
25152515
SectionName.str().c_str(),
25162516
Address,
2517-
ordinalName(Obj, Entry.ordinal()))
2517+
ordinalName(Obj, Entry.ordinal()).str().c_str())
25182518
<< Entry.symbolName() << "\n";
25192519
}
25202520
}

0 commit comments

Comments
 (0)