Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: webrtc/base/rollingaccumulator.h

Issue 1744183002: Fix some signed overflow errors causing undefined behavior (in theory). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Format and comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/random_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/rollingaccumulator.h
diff --git a/webrtc/base/rollingaccumulator.h b/webrtc/base/rollingaccumulator.h
index e1053801917955215b6f04d3b404f4ee3cc9b1fa..0c8e5fb8bdc0aee469b97ffd96374f5ef073cca4 100644
--- a/webrtc/base/rollingaccumulator.h
+++ b/webrtc/base/rollingaccumulator.h
@@ -56,7 +56,7 @@ class RollingAccumulator {
// Remove oldest sample.
T sample_to_remove = samples_[next_index_];
sum_ -= sample_to_remove;
- sum_2_ -= sample_to_remove * sample_to_remove;
+ sum_2_ -= static_cast<double>(sample_to_remove) * sample_to_remove;
if (sample_to_remove >= max_) {
max_stale_ = true;
}
@@ -70,7 +70,7 @@ class RollingAccumulator {
// Add new sample.
samples_[next_index_] = sample;
sum_ += sample;
- sum_2_ += sample * sample;
+ sum_2_ += static_cast<double>(sample) * sample;
if (count_ == 1 || sample >= max_) {
max_ = sample;
max_stale_ = false;
« no previous file with comments | « webrtc/base/random_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698