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

Commit b783f4b2 authored by Wei Jia's avatar Wei Jia
Browse files

ALooper: fix overflow

Test: cts
Bug: 118307474
Change-Id: Ief062bf644c95018bee86136971475717abbee27
parent 2d4cf009
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -170,7 +170,9 @@ void ALooper::post(const sp<AMessage> &msg, int64_t delayUs) {

    int64_t whenUs;
    if (delayUs > 0) {
        whenUs = GetNowUs() + delayUs;
        int64_t nowUs = GetNowUs();
        whenUs = (delayUs > INT64_MAX - nowUs ? INT64_MAX : nowUs + delayUs);

    } else {
        whenUs = GetNowUs();
    }
@@ -208,6 +210,9 @@ bool ALooper::loop() {

        if (whenUs > nowUs) {
            int64_t delayUs = whenUs - nowUs;
            if (delayUs > INT64_MAX / 1000) {
                delayUs = INT64_MAX / 1000;
            }
            mQueueChangedCondition.waitRelative(mLock, delayUs * 1000ll);

            return true;