diff --git a/src/Timer.cpp b/src/Timer.cpp index b2b86dc..ad4397b 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -70,6 +70,13 @@ bool Timer::setTimer( timer_t timerId, const time_t initExpr_sec, const long initExpr_nsec ) { + if (m_timerUsers.find(timerId) == m_timerUsers.end() ) { + LOG_BEGIN(Logger::ERR) + LOG_SPROP(timerId) + LOG_END("TimerId is not in the map."); + return false; + } + itimerspec its; its.it_value.tv_sec = interval_sec; its.it_value.tv_nsec = interval_nsec; diff --git a/test/test_Timer.hpp b/test/test_Timer.hpp index 9a75e1c..8c8592b 100644 --- a/test/test_Timer.hpp +++ b/test/test_Timer.hpp @@ -185,4 +185,14 @@ private: TS_ASSERT_EQUALS(timer.stopTimer( timerId ), false); } + void testSetTimerWhichIsNotInTheMap() + { + TEST_HEADER; + + Timer timer; + + timer_t timerId = (void*)1234; + TS_ASSERT_EQUALS(timer.setTimer( timerId, 1 ), false); + } + };