aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/MachOObjectFile.cpp
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2014-09-17 00:25:22 +0000
committerNick Kledzik <kledzik@apple.com>2014-09-17 00:25:22 +0000
commit3006130a8e64fdaf45fe6e40c5401cadb0e0cd4c (patch)
tree0892cf6646a0ffe4f4601f04b19b96fe4105bcf5 /llvm/lib/Object/MachOObjectFile.cpp
parent6466f43688ffc28bcdc82bb2a197bb1332f51d52 (diff)
downloadllvm-3006130a8e64fdaf45fe6e40c5401cadb0e0cd4c.zip
llvm-3006130a8e64fdaf45fe6e40c5401cadb0e0cd4c.tar.gz
llvm-3006130a8e64fdaf45fe6e40c5401cadb0e0cd4c.tar.bz2
[llvm-objdump] properly use c_str() with format("%s"). Improve getLibraryShortNameByIndex() error handling.
llvm-svn: 217930
Diffstat (limited to 'llvm/lib/Object/MachOObjectFile.cpp')
-rw-r--r--llvm/lib/Object/MachOObjectFile.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index bb973b4..94fa94c 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -1184,27 +1184,22 @@ std::error_code MachOObjectFile::getLibraryShortNameByIndex(unsigned Index,
if (Index >= Libraries.size())
return object_error::parse_failed;
- MachO::dylib_command D =
- getStruct<MachO::dylib_command>(this, Libraries[Index]);
- if (D.dylib.name >= D.cmdsize)
- return object_error::parse_failed;
-
// If the cache of LibrariesShortNames is not built up do that first for
// all the Libraries.
if (LibrariesShortNames.size() == 0) {
for (unsigned i = 0; i < Libraries.size(); i++) {
MachO::dylib_command D =
getStruct<MachO::dylib_command>(this, Libraries[i]);
- if (D.dylib.name >= D.cmdsize) {
- LibrariesShortNames.push_back(StringRef());
- continue;
- }
+ if (D.dylib.name >= D.cmdsize)
+ return object_error::parse_failed;
const char *P = (const char *)(Libraries[i]) + D.dylib.name;
StringRef Name = StringRef(P);
+ if (D.dylib.name+Name.size() >= D.cmdsize)
+ return object_error::parse_failed;
StringRef Suffix;
bool isFramework;
StringRef shortName = guessLibraryShortName(Name, isFramework, Suffix);
- if (shortName == StringRef())
+ if (shortName.empty())
LibrariesShortNames.push_back(Name);
else
LibrariesShortNames.push_back(shortName);