Skip to content

Commit 3b968e7

Browse files
committed
fix: removing invalid timers.
- Removing invalid timers should do nothing.
1 parent d13b589 commit 3b968e7

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

include/net/timers/impl/timers_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ auto timers<Interrupt>::remove(timer_id tid) noexcept -> void
144144
{
145145
// The timer id will be added to the free_ids list once
146146
// the event propagates out of the eventq.
147-
state_.events[tid].armed.clear();
147+
if (tid < state_.events.size())
148+
state_.events[tid].armed.clear();
148149
}
149150

150151
/**

tests/test_timers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ TEST(TimersTests, TimerAdd)
6767
TEST(TimersTests, ReuseTimerID)
6868
{
6969
auto timers = timers_type();
70+
71+
timers.remove(INVALID_TIMER); // Make sure this doesn't break.
72+
7073
auto timer0 = timers.add(100, [](timer_id) {});
7174
ASSERT_EQ(timer0, 0);
7275
timers.remove(timer0);

0 commit comments

Comments
 (0)