OSDN Git Service

Fix bug in edge case for statsd anomaly tracking.
authorDavid Chen <dwchen@google.com>
Tue, 20 Feb 2018 21:22:53 +0000 (13:22 -0800)
committerDavid Chen <dwchen@google.com>
Tue, 20 Feb 2018 21:22:53 +0000 (13:22 -0800)
Getting a past bucket value will always crash for anomalies
configured to track only the most recent one bucket.

Test: N/A
Change-Id: I2cd1c82fe8ba4cecb4fac21038bb5f04a60c360e

cmds/statsd/src/anomaly/AnomalyTracker.cpp

index 443d33d..6553a14 100644 (file)
@@ -149,6 +149,10 @@ void AnomalyTracker::addBucketToSum(const shared_ptr<DimToValMap>& bucket) {
 
 int64_t AnomalyTracker::getPastBucketValue(const MetricDimensionKey& key,
                                            const int64_t& bucketNum) const {
+    if (mNumOfPastBuckets == 0) {
+        return 0;
+    }
+
     const auto& bucket = mPastBuckets[index(bucketNum)];
     if (bucket == nullptr) {
         return 0;