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

Unified Diff: webrtc/common_audio/signal_processing/spl_sqrt.c

Issue 1685743003: Avoid overflow in WebRtcSpl_Sqrt (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_audio/signal_processing/spl_sqrt.c
diff --git a/webrtc/common_audio/signal_processing/spl_sqrt.c b/webrtc/common_audio/signal_processing/spl_sqrt.c
index 24db4f822ca153ceebd85d436135970a651ac559..3e01dcbd7ddade860dd4d252e625e2bf0dc0a4c0 100644
--- a/webrtc/common_audio/signal_processing/spl_sqrt.c
+++ b/webrtc/common_audio/signal_processing/spl_sqrt.c
@@ -139,6 +139,16 @@ int32_t WebRtcSpl_Sqrt(int32_t value)
A = value;
+ // The convention in this function is to calculate sqrt(abs(A)). Negate the
+ // input if it is negative.
+ if (A == WEBRTC_SPL_WORD32_MIN) {
+ // This number cannot be held in an int32_t after negating.
+ // Map it to the maximum positive value.
+ A = WEBRTC_SPL_WORD32_MAX;
+ } else if (A < 0) {
+ A = -A;
+ }
kwiberg-webrtc 2016/02/11 09:28:10 The optimizer may already be doing this for you, b
hlundin-webrtc 2016/02/11 22:02:29 Much better. Done.
+
if (A == 0)
return (int32_t)0; // sqrt(0) = 0
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698