From c08f261af02a7678e81f6c1c2ca5c8453b5cfc0e Mon Sep 17 00:00:00 2001 From: wendy lin Date: Wed, 12 Jun 2019 10:37:11 +0800 Subject: [PATCH] fix audioflinger integer multiplication overflow when underrun duration is over 3 sec, overflow happens for multiplication of nsec=sec*1000000000. Use correct format transform to solve it. Bug: 135075416 Test: run MTBF test Change-Id: I0a09ca41f2fad055ce0cfa18f936131b7a630f52 --- services/audioflinger/FastThread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/audioflinger/FastThread.cpp b/services/audioflinger/FastThread.cpp index 8b7a124c6f..47fe0b32c3 100644 --- a/services/audioflinger/FastThread.cpp +++ b/services/audioflinger/FastThread.cpp @@ -309,7 +309,7 @@ bool FastThread::threadLoop() // compute the delta value of clock_gettime(CLOCK_MONOTONIC) uint32_t monotonicNs = nsec; if (sec > 0 && sec < 4) { - monotonicNs += sec * 1000000000; + monotonicNs += sec * 1000000000U; // unsigned to prevent signed overflow. } // compute raw CPU load = delta value of clock_gettime(CLOCK_THREAD_CPUTIME_ID) uint32_t loadNs = 0; @@ -325,7 +325,7 @@ bool FastThread::threadLoop() } loadNs = nsec; if (sec > 0 && sec < 4) { - loadNs += sec * 1000000000; + loadNs += sec * 1000000000U; // unsigned to prevent signed overflow. } } else { // first time through the loop