Fix div-by-0 in NetEq's StatisticsCalculator
If a StatisticsCalculator::PeriodicUmaAverage object was created and then deleted without any samples being logged, the destructor would call the Metric() method, which calculated sum_/counter_. However, with no samples logged, counter_ is 0. This was found and verified using UBSan tests; see the bug for more info. BUG=webrtc:5490 R=ivoc@webrtc.org Review URL: https://codereview.webrtc.org/1678773003 Cr-Commit-Position: refs/heads/master@{#11534}
This commit is contained in:
committed by
Commit bot
parent
fd2be2718d
commit
e594213a2b
@ -95,7 +95,7 @@ void StatisticsCalculator::PeriodicUmaAverage::RegisterSample(int value) {
|
||||
}
|
||||
|
||||
int StatisticsCalculator::PeriodicUmaAverage::Metric() const {
|
||||
return static_cast<int>(sum_ / counter_);
|
||||
return counter_ == 0 ? 0 : static_cast<int>(sum_ / counter_);
|
||||
}
|
||||
|
||||
void StatisticsCalculator::PeriodicUmaAverage::Reset() {
|
||||
|
||||
Reference in New Issue
Block a user