From 258f46725025e48af8a4b9875b0f6a3baff53379 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 22 Aug 2025 11:16:58 -0700 Subject: [PATCH] [wakeup-tx-scheduler] fix potential integer conversion warnings (#11842) This commit resolves compiler warnings/errors related to potential integer overflows and unsafe narrowing conversions. - The type of `mTxRequestAheadTimeUs` is changed from `uint16_t` to `uint32_t` to avoid potential overflow when calculating the TX time. - A `ClampToUint16()` utility is now used before setting the rendezvous time. This safely converts the calculated `rendezvousTimeUs` to a 16-bit integer, preventing a narrowing conversion warning. --- src/core/mac/wakeup_tx_scheduler.cpp | 3 ++- src/core/mac/wakeup_tx_scheduler.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/mac/wakeup_tx_scheduler.cpp b/src/core/mac/wakeup_tx_scheduler.cpp index 58fd83368..2ae158f16 100644 --- a/src/core/mac/wakeup_tx_scheduler.cpp +++ b/src/core/mac/wakeup_tx_scheduler.cpp @@ -110,7 +110,8 @@ Mac::TxFrame *WakeupTxScheduler::PrepareWakeupFrame(Mac::TxFrames &aTxFrames) // the "free space" between the "n+1"-th and "n+2"-th wake-up frame. rendezvousTimeUs = mIntervalUs; rendezvousTimeUs += (mIntervalUs - (kWakeupFrameLength + kParentRequestLength) * kOctetDuration) / 2; - frame->GetRendezvousTimeIe()->SetRendezvousTime(rendezvousTimeUs / kUsPerTenSymbols); + + frame->GetRendezvousTimeIe()->SetRendezvousTime(ClampToUint16(rendezvousTimeUs / kUsPerTenSymbols)); connectionIe = frame->GetConnectionIe(); connectionIe->SetRetryInterval(kConnectionRetryInterval); diff --git a/src/core/mac/wakeup_tx_scheduler.hpp b/src/core/mac/wakeup_tx_scheduler.hpp index 2ba9edc94..650934a23 100644 --- a/src/core/mac/wakeup_tx_scheduler.hpp +++ b/src/core/mac/wakeup_tx_scheduler.hpp @@ -119,7 +119,7 @@ private: Mac::ExtAddress mWedAddress; TimeMicro mTxTimeUs; // Point in time when the next TX occurs. TimeMicro mTxEndTimeUs; // Point in time when the wake-up sequence is over. - uint16_t mTxRequestAheadTimeUs; // How much ahead the TX MAC operation needs to be requested. + uint32_t mTxRequestAheadTimeUs; // How much ahead the TX MAC operation needs to be requested. uint16_t mIntervalUs; // Interval between consecutive wake-up frames. WakeupTimer mTimer; bool mIsRunning;