Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab3c6a5b authored by Phil Burk's avatar Phil Burk
Browse files

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
parent fd1ea436
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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;
    }