Fix integer sanitizer in FastMixerDumpState.
Prevent FastMixerDumpState::dump(int) from throwing a runtime error on
integer sanitized builds.
runtime error: unsigned integer overflow: 3912 - 36680 cannot be
represented in type 'unsigned int'
The overflow looks intentional, so this refactors the code to use
the builtin overflow function.
Bug: 30969751
Test: Compiled and device boots.
Change-Id: Ic84a1bd08839fe1af7f3b5318cd8d6ccee777443
Merged-In: Ic84a1bd08839fe1af7f3b5318cd8d6ccee777443
diff --git a/services/audioflinger/FastMixerDumpState.cpp b/services/audioflinger/FastMixerDumpState.cpp
index 6475f22..2e4fb8c 100644
--- a/services/audioflinger/FastMixerDumpState.cpp
+++ b/services/audioflinger/FastMixerDumpState.cpp
@@ -78,7 +78,12 @@
uint32_t bounds = mBounds;
uint32_t newestOpen = bounds & 0xFFFF;
uint32_t oldestClosed = bounds >> 16;
- uint32_t n = (newestOpen - oldestClosed) & 0xFFFF;
+
+ //uint32_t n = (newestOpen - oldestClosed) & 0xFFFF;
+ uint32_t n;
+ __builtin_sub_overflow(newestOpen, oldestClosed, &n);
+ n = n & 0xFFFF;
+
if (n > mSamplingN) {
ALOGE("too many samples %u", n);
n = mSamplingN;