Skip to content

Commit

Permalink
added asserts to make sure Beats::ConstIterator -= and += respectivel…
Browse files Browse the repository at this point in the history
…y result in a earlier or later position
  • Loading branch information
m0dB committed Sep 24, 2023
1 parent 6caebd2 commit ccaa68f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/track/beats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Beats::ConstIterator Beats::ConstIterator::operator+=(Beats::ConstIterator::diff

DEBUG_ASSERT(n > 0);
const int beatOffset = m_beatOffset + n;
const auto origValue = m_value;
(void)origValue;

// Detect integer overflow
if (beatOffset < m_beatOffset) {
Expand All @@ -69,6 +71,7 @@ Beats::ConstIterator Beats::ConstIterator::operator+=(Beats::ConstIterator::diff
m_it = m_beats->m_markers.cend();
m_beatOffset = std::numeric_limits<Beats::ConstIterator::difference_type>::max();
updateValue();
DEBUG_ASSERT(m_value > origValue);
return *this;
}

Expand All @@ -78,6 +81,7 @@ Beats::ConstIterator Beats::ConstIterator::operator+=(Beats::ConstIterator::diff
m_it++;
}
updateValue();
DEBUG_ASSERT(m_value > origValue);
return *this;
}

Expand All @@ -104,6 +108,8 @@ Beats::ConstIterator Beats::ConstIterator::operator-=(Beats::ConstIterator::diff

DEBUG_ASSERT(n > 0);
const int beatOffset = m_beatOffset - n;
const auto origValue = m_value;
(void)origValue;

// Detect integer overflow
if (beatOffset > m_beatOffset) {
Expand All @@ -112,6 +118,7 @@ Beats::ConstIterator Beats::ConstIterator::operator-=(Beats::ConstIterator::diff
m_it = m_beats->m_markers.cbegin();
m_beatOffset = std::numeric_limits<Beats::ConstIterator::difference_type>::lowest();
updateValue();
DEBUG_ASSERT(m_value < origValue);
return *this;
}

Expand All @@ -121,6 +128,7 @@ Beats::ConstIterator Beats::ConstIterator::operator-=(Beats::ConstIterator::diff
m_beatOffset += m_it->beatsTillNextMarker();
}
updateValue();
DEBUG_ASSERT(m_value < origValue);
return *this;
}

Expand Down Expand Up @@ -452,8 +460,7 @@ Beats::ConstIterator Beats::iteratorFrom(audio::FramePos position) const {
it = std::lower_bound(cfirstmarker(), clastmarker() + 1, position);
}
DEBUG_ASSERT(it == cbegin() || it == cend() || *it >= position);
DEBUG_ASSERT(it == cbegin() || it == cend() ||
(*it >= position && *std::prev(it) < position));
DEBUG_ASSERT(it == cbegin() || it == cend() || *it > *std::prev(it));
return it;
}

Expand Down

0 comments on commit ccaa68f

Please sign in to comment.