Skip to content

Commit

Permalink
Use size_t/ssize_t for nValue-related variables
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBE committed Oct 10, 2023
1 parent 15dc513 commit 44cace2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
memmove(data->values + (data->nValues - oldNValues), data->values, oldNValues * sizeof(*data->values));
memset(data->values, 0, (data->nValues - oldNValues) * sizeof(*data->values));
}
const int nValues = data->nValues;
const size_t nValues = data->nValues;

const char* const* GraphMeterMode_dots;
int GraphMeterMode_pixPerRow;
Expand All @@ -327,18 +327,20 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
struct timeval delay = { .tv_sec = globalDelay / 10, .tv_usec = (globalDelay % 10) * 100000L };
timeradd(&host->realtime, &delay, &(data->time));

for (int i = 0; i < nValues - 1; i++)
for (size_t i = 0; i < nValues - 1; i++)
data->values[i] = data->values[i + 1];

data->values[nValues - 1] = sumPositiveValues(this->values, this->curItems);
}

int i = nValues - (w * 2), k = 0;
assert(nValues <= SSIZE_MAX);
ssize_t i = (ssize_t)nValues - (w * 2);
ssize_t k = 0;
if (i < 0) {
k = -i / 2;
i = 0;
}
for (; i < nValues - 1; i += 2, k++) {
for (; i < (ssize_t)nValues - 1; i += 2, k++) {
int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT;
if (this->total < 1)
this->total = 1;
Expand Down

0 comments on commit 44cace2

Please sign in to comment.