Fix crash when IntervalMapOverlaps::advanceTo moves past the last overlap.
llvm-svn: 122081
This commit is contained in:
parent
4698e938b1
commit
213de04d75
|
@ -2036,6 +2036,8 @@ class IntervalMapOverlaps {
|
||||||
/// either meets end.
|
/// either meets end.
|
||||||
/// Don't move the iterators if they are already overlapping.
|
/// Don't move the iterators if they are already overlapping.
|
||||||
void advance() {
|
void advance() {
|
||||||
|
if (!valid())
|
||||||
|
return;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Make a.end > b.start.
|
// Make a.end > b.start.
|
||||||
posA.advanceTo(posB.start());
|
posA.advanceTo(posB.start());
|
||||||
|
@ -2052,10 +2054,7 @@ public:
|
||||||
/// IntervalMapOverlaps - Create an iterator for the overlaps of a and b.
|
/// IntervalMapOverlaps - Create an iterator for the overlaps of a and b.
|
||||||
IntervalMapOverlaps(const MapA &a, const MapB &b)
|
IntervalMapOverlaps(const MapA &a, const MapB &b)
|
||||||
: posA(b.empty() ? a.end() : a.find(b.start())),
|
: posA(b.empty() ? a.end() : a.find(b.start())),
|
||||||
posB(posA.valid() ? b.find(posA.start()) : b.end()) {
|
posB(posA.valid() ? b.find(posA.start()) : b.end()) { advance(); }
|
||||||
if (valid())
|
|
||||||
advance();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// valid - Return true if iterator is at an overlap.
|
/// valid - Return true if iterator is at an overlap.
|
||||||
bool valid() const {
|
bool valid() const {
|
||||||
|
@ -2090,7 +2089,7 @@ public:
|
||||||
// Second half-loop of advance().
|
// Second half-loop of advance().
|
||||||
posB.advanceTo(posA.start());
|
posB.advanceTo(posA.start());
|
||||||
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
|
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
|
||||||
return ;
|
return;
|
||||||
advance();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2098,7 +2097,7 @@ public:
|
||||||
void skipB() {
|
void skipB() {
|
||||||
++posB;
|
++posB;
|
||||||
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
|
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
|
||||||
return;
|
return;
|
||||||
advance();
|
advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -586,7 +586,11 @@ TEST(IntervalMapOverlapsTest, SmallMaps) {
|
||||||
ASSERT_TRUE(BA.valid());
|
ASSERT_TRUE(BA.valid());
|
||||||
EXPECT_EQ(3u, BA.a().start());
|
EXPECT_EQ(3u, BA.a().start());
|
||||||
EXPECT_EQ(4u, BA.b().start());
|
EXPECT_EQ(4u, BA.b().start());
|
||||||
++BA;
|
// advance past end.
|
||||||
|
BA.advanceTo(6);
|
||||||
|
EXPECT_FALSE(BA.valid());
|
||||||
|
// advance an invalid iterator.
|
||||||
|
BA.advanceTo(7);
|
||||||
EXPECT_FALSE(BA.valid());
|
EXPECT_FALSE(BA.valid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue