Change total sample count type to 64 bit
We encounter aborts due to globally enabled overflow sanitization.
- Change mTotalSmp to 64 bit to avoid crashes
The behavior of this component is still not well-defined if
ToneGenerator plays for long durations.
Bug: 229549191
Test: Compiles
Change-Id: Idb7c0ae9272ece837663f4ab8ee1be72c0c28857
diff --git a/media/libaudioclient/ToneGenerator.cpp b/media/libaudioclient/ToneGenerator.cpp
index 9b43f3c..dd3f86e 100644
--- a/media/libaudioclient/ToneGenerator.cpp
+++ b/media/libaudioclient/ToneGenerator.cpp
@@ -17,6 +17,7 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "ToneGenerator"
+#include <inttypes.h>
#include <utility>
#include <math.h>
@@ -1229,7 +1230,8 @@
sec = sec * 1000 + nsec / 1000000; // duration in milliseconds
mMaxSmp = (unsigned int)(((int64_t)sec * mSamplingRate) / 1000);
}
- ALOGV("stopTone() forcing mMaxSmp to %d, total for far %d", mMaxSmp, mTotalSmp);
+ ALOGV("stopTone() forcing mMaxSmp to %d, total for far %" PRIu64, mMaxSmp,
+ mTotalSmp);
} else {
mState = TONE_STOPPING;
}
@@ -1399,7 +1401,7 @@
mNextSegSmp = TONEGEN_INF; // forced to skip state machine management below
}
- if (mTotalSmp > mNextSegSmp) {
+ if (mTotalSmp > mNextSegSmp && mNextSegSmp != TONEGEN_INF) {
// Time to go to next sequence segment
ALOGV("End Segment, time: %d", (unsigned int)(systemTime()/1000000));