Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions include/swift/Reflection/TypeRefBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class ReflectionSectionIteratorBase
: OriginalSize(Size), Cur(Cur), Size(Size), Name(Name) {
if (Size != 0) {
auto NextRecord = this->operator*();
if (!NextRecord) {
// NULL record pointer, don't attempt to proceed. Setting size to 0 will
// make this iterator compare equal to the end iterator.
this->Size = 0;
return;
}
auto NextSize = Self::getCurrentRecordSize(NextRecord);
if (NextSize > Size) {
std::cerr << "!!! Reflection section too small to contain first record\n" << std::endl;
Expand All @@ -109,7 +115,9 @@ class ReflectionSectionIteratorBase
<< ", size of first record: "
<< NextSize
<< std::endl;
abort();
// Set this iterator equal to the end. This section is effectively
// empty.
this->Size = 0;
}
}
}
Expand Down Expand Up @@ -149,14 +157,18 @@ class ReflectionSectionIteratorBase
std::cerr << std::hex << std::setw(2) << (int)p[i] << " ";
}
std::cerr << std::endl;
abort();
Size = 0; // Set this iterator equal to the end.
}
}

return asImpl();
}

bool operator==(const Self &other) const {
// Size = 0 means we're at the end even if Cur doesn't match. This allows
// iterators that encounter an incorrect size to safely end iteration.
if (Size == 0 && other.Size == 0)
return true;
return Cur == other.Cur && Size == other.Size;
}

Expand Down