Skip to content

Commit

Permalink
[cli] fix the issue of overflow when calculating ping statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
gytxxsy committed Dec 4, 2024
1 parent 2868c9c commit 91e8f4e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cli/cli_ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ void PingSender::HandlePingStatistics(const otPingSenderStatistics *aStatistics)

if (aStatistics->mReceivedCount != 0)
{
uint32_t avgRoundTripTime = 1000 * aStatistics->mTotalRoundTripTime / aStatistics->mReceivedCount;
uint32_t avgRoundTripTime =
1000 * static_cast<uint64_t>(aStatistics->mTotalRoundTripTime) / aStatistics->mReceivedCount;

OutputFormat(" Round-trip min/avg/max = %u/%u.%u/%u ms.", aStatistics->mMinRoundTripTime,
static_cast<uint16_t>(avgRoundTripTime / 1000), static_cast<uint16_t>(avgRoundTripTime % 1000),
Expand Down

0 comments on commit 91e8f4e

Please sign in to comment.