diff options
author | Lang Hames <lhames@gmail.com> | 2016-10-05 21:20:00 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-10-05 21:20:00 +0000 |
commit | a5e873e2a1c079028ffc3e4aaa36a1decf204ed0 (patch) | |
tree | cf357d2726977e17fbcd8cf32ddc3d213f78ef1f /llvm/lib/Object/Archive.cpp | |
parent | a01bccdbe613f5e65fa8da2fb07d6b9b66d203bf (diff) | |
download | bcm5719-llvm-a5e873e2a1c079028ffc3e4aaa36a1decf204ed0.tar.gz bcm5719-llvm-a5e873e2a1c079028ffc3e4aaa36a1decf204ed0.zip |
[Object] Fix a crash in Archive::child_iterator's default constructor.
To be default constructible, Archive::child_iterator needs to be able to
construct an Archive::Child with a null parent, however Archive::Child's
constructor always dereferenced its Parent argument to compute the remaining
archive size. This commit fixes Archive::Child's constructor to only do the
size calculation when the parent is non-null.
llvm-svn: 283387
Diffstat (limited to 'llvm/lib/Object/Archive.cpp')
-rw-r--r-- | llvm/lib/Object/Archive.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp index 73761fa73db..9a83f69705c 100644 --- a/llvm/lib/Object/Archive.cpp +++ b/llvm/lib/Object/Archive.cpp @@ -306,8 +306,11 @@ Archive::Child::Child(const Archive *Parent, StringRef Data, } Archive::Child::Child(const Archive *Parent, const char *Start, Error *Err) - : Parent(Parent), Header(Parent, Start, Parent->getData().size() - - (Start - Parent->getData().data()), Err) { + : Parent(Parent), + Header(Parent, Start, + Parent + ? Parent->getData().size() - (Start - Parent->getData().data()) + : 0, Err) { if (!Start) return; @@ -441,7 +444,7 @@ Expected<Archive::Child> Archive::Child::getNext() const { // Check to see if this is at the end of the archive. if (NextLoc == Parent->Data.getBufferEnd()) - return Child(Parent, nullptr, nullptr); + return Child(nullptr, nullptr, nullptr); // Check to see if this is past the end of the archive. if (NextLoc > Parent->Data.getBufferEnd()) { @@ -768,7 +771,7 @@ Archive::child_iterator Archive::child_begin(Error &Err, } Archive::child_iterator Archive::child_end() const { - return child_iterator(Child(this, nullptr, nullptr), nullptr); + return child_iterator(Child(nullptr, nullptr, nullptr), nullptr); } StringRef Archive::Symbol::getName() const { |