Skip to content

Commit

Permalink
Permit zero items in drawing a Graph meter
Browse files Browse the repository at this point in the history
A meter with zero items used to be allowed in GraphMeterMode_draw()
until commit 398fb30 added a
"nonnull" constraint to sumPositiveValues() function. It caused the
use case in GraphMeterMode_draw() an undefined behavior.

Fix the caller code so that a meter with `curItems` being 0 is allowed
again in Graph mode (`values` may be NULL when `curItems` is 0).
  • Loading branch information
Explorer09 authored and BenBE committed Jul 23, 2024
1 parent 1887699 commit cf72728
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {

memmove(&data->values[0], &data->values[1], (nValues - 1) * sizeof(*data->values));

data->values[nValues - 1] = sumPositiveValues(this->values, this->curItems);
data->values[nValues - 1] = 0.0;
if (this->curItems > 0) {
assert(this->values);
data->values[nValues - 1] = sumPositiveValues(this->values, this->curItems);
}
}

if (w <= 0)
Expand Down

0 comments on commit cf72728

Please sign in to comment.