Skip to content

Commit

Permalink
[wpimath] Fix invalid iterator access in TimeInterpolatableBuffer (#5138
Browse files Browse the repository at this point in the history
)
  • Loading branch information
virtuald authored Feb 27, 2023
1 parent 099d048 commit e5c4c6b
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ class TimeInterpolatableBuffer {
m_pastSnapshots.begin(), m_pastSnapshots.end(), time,
[](auto t, const auto& pair) { return t < pair.first; });

// Don't access this before ensuring first_after isn't first.
auto last_not_greater_than = first_after - 1;

if (last_not_greater_than == m_pastSnapshots.begin() ||
if (first_after == m_pastSnapshots.begin() ||
last_not_greater_than == m_pastSnapshots.begin() ||
last_not_greater_than->first < time) {
// Two cases handled together:
// 1. All entries come after the sample
Expand Down Expand Up @@ -125,6 +127,10 @@ class TimeInterpolatableBuffer {
m_pastSnapshots.begin(), m_pastSnapshots.end(), time,
[](const auto& pair, auto t) { return t > pair.first; });

if (upper_bound == m_pastSnapshots.begin()) {
return upper_bound->second;
}

auto lower_bound = upper_bound - 1;

double t = ((time - lower_bound->first) /
Expand Down

0 comments on commit e5c4c6b

Please sign in to comment.