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

Unified Diff: webrtc/common_audio/signal_processing/dot_product_with_scale.cc

Issue 2717123004: Avoid overflow in WebRtcSpl_DotProductWithScale (Closed)
Patch Set: Remove wd4334 Created 3 years, 9 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
Index: webrtc/common_audio/signal_processing/dot_product_with_scale.cc
diff --git a/webrtc/common_audio/signal_processing/dot_product_with_scale.c b/webrtc/common_audio/signal_processing/dot_product_with_scale.cc
similarity index 85%
rename from webrtc/common_audio/signal_processing/dot_product_with_scale.c
rename to webrtc/common_audio/signal_processing/dot_product_with_scale.cc
index 1302d62541266fdc45b07576de5ff5026d69032f..4067ab5599614c2ab5bc32ac7cfe17e42b64cfac 100644
--- a/webrtc/common_audio/signal_processing/dot_product_with_scale.c
+++ b/webrtc/common_audio/signal_processing/dot_product_with_scale.cc
@@ -8,13 +8,15 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
+#include "webrtc/common_audio/signal_processing/dot_product_with_scale.h"
+
+#include "webrtc/base/safe_conversions.h"
int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
const int16_t* vector2,
size_t length,
int scaling) {
- int32_t sum = 0;
+ int64_t sum = 0;
size_t i = 0;
/* Unroll the loop to improve performance. */
@@ -28,5 +30,5 @@ int32_t WebRtcSpl_DotProductWithScale(const int16_t* vector1,
sum += (vector1[i] * vector2[i]) >> scaling;
}
- return sum;
+ return rtc::saturated_cast<int32_t>(sum);
}

Powered by Google App Engine
This is Rietveld 408576698