Skip to content

Commit

Permalink
findTopCellItem() handle underflow (f5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 7, 2024
1 parent 30f1565 commit cb20969
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ static uint8_t GraphMeterMode_findTopCellItem(const Meter* this, double scaledTo

double area = (value / scaledTotal) * (double)(int)graphHeight;

// if (maxValue <= 0.0)
// if (topCellItem >= i)
if (topCellItem > i) {
// if (topCellItem > i)
if (maxValue <= 0.0 && !hasArea) {
double topPoint = (valueSum / scaledTotal) * (double)(int)graphHeight;
assert(topPoint >= 0.0);

Expand All @@ -426,24 +426,24 @@ static uint8_t GraphMeterMode_findTopCellItem(const Meter* this, double scaledTo

if (area > topPoint - (double)(int)topCell) {
hasArea = true;
maxValue = topPoint - (double)(int)topCell;
maxValue = topPoint - (double)(int)topCell;
} else {
maxValue = value;
}
}
topCellItem = i;
} else {
if (hasArea) {
if (area >= maxValue) {
hasArea = false;
maxValue = value;
topCellItem = i;
}
}
} else {
if (value >= maxValue) {
maxValue = value;
topCellItem = i;
}
}
}
}
}
return topCellItem;
Expand Down

0 comments on commit cb20969

Please sign in to comment.