Return zero delta when delta is not computed

Bug: 197162116
Test: atest libbattery_test

Change-Id: If75e1f127810dead17b272a5f1aff08818ea1761
diff --git a/libs/battery/MultiStateCounter.h b/libs/battery/MultiStateCounter.h
index 112fb85..03e1f2a 100644
--- a/libs/battery/MultiStateCounter.h
+++ b/libs/battery/MultiStateCounter.h
@@ -168,6 +168,8 @@
 
 template <class T>
 const T& MultiStateCounter<T>::updateValue(const T& value, time_t timestamp) {
+    T* returnValue = &emptyValue;
+
     // If the counter is disabled, we ignore the update, except when the counter got disabled after
     // the previous update, in which case we still need to pick up the residual delta.
     if (isEnabled || lastUpdateTimestamp < lastStateChangeTimestamp) {
@@ -178,6 +180,7 @@
         if (lastUpdateTimestamp >= 0) {
             if (timestamp > lastUpdateTimestamp) {
                 if (delta(lastValue, value, &deltaValue)) {
+                    returnValue = &deltaValue;
                     time_t timeSinceUpdate = timestamp - lastUpdateTimestamp;
                     for (int i = 0; i < stateCount; i++) {
                         time_t timeInState = states[i].timeInStateSinceUpdate;
@@ -201,7 +204,7 @@
     }
     lastValue = value;
     lastUpdateTimestamp = timestamp;
-    return deltaValue;
+    return *returnValue;
 }
 
 template <class T>