Skip to content

Commit

Permalink
Clamp graph meter values in "double" type
Browse files Browse the repository at this point in the history
A meter's "drawData.values[i] / total" quotient could overflow an
integer type (the resulting value would be "unspecified"). Clamp the
values in floating point type to prevent that.
  • Loading branch information
Explorer09 authored and BenBE committed Aug 1, 2024
1 parent a8b5d68 commit 8edd449
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
for (int col = 0; i < nValues - 1; i += 2, col++) {
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
double total = MAXIMUM(this->total, 1);
int v1 = CLAMP((int) lround(data->values[i] / total * pix), 1, pix);
int v2 = CLAMP((int) lround(data->values[i + 1] / total * pix), 1, pix);
int v1 = (int) lround(CLAMP(data->values[i] / total * pix, 1.0, pix));
int v2 = (int) lround(CLAMP(data->values[i + 1] / total * pix, 1.0, pix));

int colorIdx = GRAPH_1;
for (int line = 0; line < GRAPH_HEIGHT; line++) {
Expand Down

0 comments on commit 8edd449

Please sign in to comment.