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

Unified Diff: third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp

Issue 2582323003: Test for power of two safely (Closed)
Patch Set: Created 4 years 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: third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp b/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
index b4cdd95f912dc21f77e63d440c30cef966929599..a0d1e56a3c068de3f3ff05750ab349935d068fe0 100644
--- a/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp
@@ -63,11 +63,9 @@ RealtimeAnalyser::RealtimeAnalyser()
bool RealtimeAnalyser::setFftSize(size_t size) {
DCHECK(isMainThread());
- // Only allow powers of two.
- unsigned log2size = static_cast<unsigned>(log2(size));
- bool isPOT(1UL << log2size == size);
-
- if (!isPOT || size > MaxFFTSize || size < MinFFTSize)
+ // Only allow powers of two within the allowed range.
+ if (size > MaxFFTSize || size < MinFFTSize ||
+ !AudioUtilities::isPowerOfTwo(size))
return false;
if (m_fftSize != size) {

Powered by Google App Engine
This is Rietveld 408576698