Fix a crash happening in NBLog's 'writeHistToFile'
The issue was in the possibility of the 'intervals' vector being
empty if the provided 'samples' vector contains only one
element. That leads to 'intervals.end()' being passed to
'intervals.erase()', and vector::erase produces undefined
behaviour in that case.
I see no other calls to 'erase' or 'max_element' in libnbaio,
so that should be the only fix needed.
Bug: 62536501
Test: see test case at bug
Change-Id: I37f93fa42030ed6f5bcb2d46b0a7a2c0af3c82e4
diff --git a/media/libnbaio/NBLog.cpp b/media/libnbaio/NBLog.cpp
index 48ffb01..ebb90c8 100644
--- a/media/libnbaio/NBLog.cpp
+++ b/media/libnbaio/NBLog.cpp
@@ -917,10 +917,10 @@
static const char* const kName = (char *)"/data/misc/audioserver/sample_results.txt";
// stores deltas between the samples
std::vector<int64_t> intervals;
- if (samples.size() == 0) return;
for (size_t i = 1; i < samples.size(); ++i) {
intervals.push_back(deltaMs(samples[i - 1], samples[i]));
}
+ if (intervals.empty()) return;
// Deletes maximum value in a histogram. Temp quick fix.
// FIXME: need to find root cause of approx. 35th element from the end
// consistently being an outlier in the first histogram of a flush