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
gugelfrei
Phil Burk 6 years ago
parent fd1ea436c6
commit ab3c6a5b75

@ -66,8 +66,9 @@ status_t AudioStreamOut::getRenderPosition(uint64_t *frames)
// 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;
}

Loading…
Cancel
Save