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

Commit 386bfa24 authored by Atneya Nair's avatar Atneya Nair
Browse files

Handle next segment wraparound gracefully

Since global overflow/wraparound sanitization is enabled,
mNextSegSmp can wraparound 32 bits and abort.
In this case, we clamp to UINT_MAX to handle this condition
gracefully. We already use this value as a signal to not
transition to a new segment of tone generation.

Test: Compiles
Bug: 229549191
Change-Id: I2e937e3ea2c43f0f021c48d8ad5cebf2416c5a74
parent 1b9a3cf9
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1485,8 +1485,11 @@ size_t ToneGenerator::onMoreData(const AudioTrack::Buffer& buffer) {
            }

            // Update next segment transition position. No harm to do it also for last segment as
            // mNextSegSmp won't be used any more
            mNextSegSmp += (mpToneDesc->segments[mCurSegment].duration * mSamplingRate) / 1000;
            // mNextSegSmp won't be used any more.
            // Handle 32 bit wraparound gracefully.
            const uint64_t res = static_cast<uint64_t>(mNextSegSmp) +
                    (mpToneDesc->segments[mCurSegment].duration * mSamplingRate) / 1000;
            mNextSegSmp = static_cast<uint32_t>(std::min<uint64_t>(TONEGEN_INF, res));

        } else {
            // Inside a segment keep tone ON or OFF