diff --git a/src/core/thread/link_quality.cpp b/src/core/thread/link_quality.cpp index b2adbdcc7..67475401b 100644 --- a/src/core/thread/link_quality.cpp +++ b/src/core/thread/link_quality.cpp @@ -117,7 +117,8 @@ exit: void LqiAverager::Add(uint8_t aLqi) { - uint8_t count; + uint8_t count; + uint16_t newAverage; if (mCount < NumericLimits::kMax) { @@ -126,7 +127,10 @@ void LqiAverager::Add(uint8_t aLqi) count = Min(static_cast(1 << kCoeffBitShift), mCount); - mAverage = static_cast(((mAverage * (count - 1)) + aLqi) / count); + newAverage = mAverage; + newAverage = (newAverage * (count - 1) + aLqi) / count; + + mAverage = static_cast(newAverage); } void LinkQualityInfo::Clear(void)