audioflinger: allow unsigned overflow in getRenderPosition
Overflow is expected when 32-bit counter wraps after several hours.
So prevent sanitization from causing a crash.
Bug: 122986677
Test: run a stream for more than 12 hours so the position overflows
Change-Id: I0f397f193288c2493a2036f67849bb12a9c9f221
diff --git a/services/audioflinger/AudioStreamOut.cpp b/services/audioflinger/AudioStreamOut.cpp
index 1d4b3fe..a60a5f2 100644
--- a/services/audioflinger/AudioStreamOut.cpp
+++ b/services/audioflinger/AudioStreamOut.cpp
@@ -66,8 +66,9 @@
// Maintain a 64-bit render position using the 32-bit result from the HAL.
// This delta calculation relies on the arithmetic overflow behavior
// of integers. For example (100 - 0xFFFFFFF0) = 116.
- uint32_t truncatedPosition = (uint32_t)mRenderPosition;
- int32_t deltaHalPosition = (int32_t)(halPosition - truncatedPosition);
+ const uint32_t truncatedPosition = (uint32_t)mRenderPosition;
+ int32_t deltaHalPosition; // initialization not needed, overwitten by __builtin_sub_overflow()
+ (void) __builtin_sub_overflow(halPosition, truncatedPosition, &deltaHalPosition);
if (deltaHalPosition > 0) {
mRenderPosition += deltaHalPosition;
}