Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d865240 authored by Per Andersson's avatar Per Andersson Committed by Johan Redestig
Browse files

Adding a sanity test in the while loop in readHistory()

Adding a sanity test in the while loop in readHistory() which
is useful in case the file read (batterystats.bin), is corrupt.
The file can get corrupt (missing end of file marker -1) if
writeHistory fails for some reason. Without this change
readHistory will continue looping untill an OutOfMemory is
thrown.

Change-Id: I3418d258e7cb99aa2f9d934c9449a19806499ce4
parent 7118bdec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4563,7 +4563,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        mHistory = mHistoryEnd = mHistoryCache = null;
        mHistoryBaseTime = 0;
        long time;
        while ((time=in.readLong()) >= 0) {
        while (in.dataAvail() > 0 && (time=in.readLong()) >= 0) {
            HistoryItem rec = new HistoryItem(time, in);
            addHistoryRecordLocked(rec);
            if (rec.time > mHistoryBaseTime) {