llvm.org GIT mirror llvm / 1911873
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283387 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
2 changed file(s) with 8 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
9191 Child(const Archive *Parent, StringRef Data, uint16_t StartOfFile);
9292
9393 bool operator ==(const Child &other) const {
94 assert(Parent == other.Parent);
94 assert(!Parent || !other.Parent || Parent == other.Parent);
9595 return Data.begin() == other.Data.begin();
9696 }
9797
305305 }
306306
307307 Archive::Child::Child(const Archive *Parent, const char *Start, Error *Err)
308 : Parent(Parent), Header(Parent, Start, Parent->getData().size() -
309 (Start - Parent->getData().data()), Err) {
308 : Parent(Parent),
309 Header(Parent, Start,
310 Parent
311 ? Parent->getData().size() - (Start - Parent->getData().data())
312 : 0, Err) {
310313 if (!Start)
311314 return;
312315
440443
441444 // Check to see if this is at the end of the archive.
442445 if (NextLoc == Parent->Data.getBufferEnd())
443 return Child(Parent, nullptr, nullptr);
446 return Child(nullptr, nullptr, nullptr);
444447
445448 // Check to see if this is past the end of the archive.
446449 if (NextLoc > Parent->Data.getBufferEnd()) {
767770 }
768771
769772 Archive::child_iterator Archive::child_end() const {
770 return child_iterator(Child(this, nullptr, nullptr), nullptr);
773 return child_iterator(Child(nullptr, nullptr, nullptr), nullptr);
771774 }
772775
773776 StringRef Archive::Symbol::getName() const {