Skip to content

Commit

Permalink
Cap the maximum size of GraphData buffer to 32768 values.
Browse files Browse the repository at this point in the history
Signed-off-by: Kang-Che Sung <[email protected]>
  • Loading branch information
Explorer09 authored and BenBE committed Oct 10, 2023
1 parent 1a9ae38 commit 83041f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,19 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
return;

GraphData* data = &this->drawData;
if ((size_t)w * 2 > data->nValues) {
if ((size_t)w * 2 > data->nValues && MAX_METER_GRAPHDATA_VALUES > data->nValues) {
size_t oldNValues = data->nValues;
data->nValues = MAXIMUM(oldNValues + (oldNValues / 2), (size_t)w * 2);
data->nValues = MAXIMUM(oldNValues + oldNValues / 2, (size_t)w * 2);
data->nValues = MINIMUM(data->nValues, MAX_METER_GRAPHDATA_VALUES);
data->values = xReallocArray(data->values, data->nValues, sizeof(*data->values));
memmove(data->values + (data->nValues - oldNValues), data->values, oldNValues * sizeof(*data->values));
memset(data->values, 0, (data->nValues - oldNValues) * sizeof(*data->values));
}
const size_t nValues = data->nValues;
if ((size_t)w * 2 > nValues) {
x += w - nValues / 2;
w = nValues / 2;
}

const Machine* host = this->host;
if (!timercmp(&host->realtime, &(data->time), <)) {
Expand Down
1 change: 1 addition & 0 deletions Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ in the source distribution for its full text.


#define METER_TXTBUFFER_LEN 256
#define MAX_METER_GRAPHDATA_VALUES 32768

#define METER_BUFFER_CHECK(buffer, size, written) \
do { \
Expand Down

0 comments on commit 83041f3

Please sign in to comment.