From 04f13fef8b9f837a27f80153b9ebbd6addd69eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Duda?= Date: Thu, 13 Oct 2016 15:23:00 +0200 Subject: [PATCH] Trickle Timer: Allow other modules to set Imin equal to Imax (#802) Currently, when TrickleTimer:Start method is called with same aIntervalMin and aIntervalMax, the remainder used to calculate I is 0, which cause an Arithmetic Error and crash of the program. --- src/core/common/trickle_timer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/common/trickle_timer.cpp b/src/core/common/trickle_timer.cpp index 577342cbb..2fbde46fd 100644 --- a/src/core/common/trickle_timer.cpp +++ b/src/core/common/trickle_timer.cpp @@ -71,7 +71,14 @@ void TrickleTimer::Start(uint32_t aIntervalMin, uint32_t aIntervalMax, Mode aMod mMode = aMode; // Initialize I to [Imin, Imax] - I = Imin + otPlatRandomGet() % (Imax - Imin); + if (Imin == Imax) + { + I = Imin; + } + else + { + I = Imin + otPlatRandomGet() % (Imax - Imin); + } // Start a new interval StartNewInterval();