mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpimath] Fix invalid iterator access in TimeInterpolatableBuffer (#5138)
This commit is contained in:
@@ -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
|
||||
@@ -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) /
|
||||
|
||||
Reference in New Issue
Block a user