From 7784c99f4672fb46b02f00877069571d377223c5 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 12 Oct 2023 00:46:48 +0800 Subject: [PATCH] Record new graph data even when no graph is drawn. Fixes a regression caused by 74b28849c4ee7234aa6018667ff6c8c9a6b41273. When a graph meter is too narrow to draw the graph, but the graph data buffer is allocated, the meter should keep recording new values. Signed-off-by: Kang-Che Sung --- Meter.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Meter.c b/Meter.c index bb137aad42..b17df4a478 100644 --- a/Meter.c +++ b/Meter.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "Meter.h" #include +#include #include #include #include @@ -295,11 +296,10 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { mvaddnstr(y, x, caption, captionLen); x += captionLen; w -= captionLen; - if (w <= 0) - return; GraphData* data = &this->drawData; - if ((size_t)w * 2 > data->nValues && MAX_METER_GRAPHDATA_VALUES > data->nValues) { + assert(data->nValues / 2 <= INT_MAX); + if (w > (int)(data->nValues / 2) && MAX_METER_GRAPHDATA_VALUES > data->nValues) { size_t oldNValues = data->nValues; data->nValues = MAXIMUM(oldNValues + oldNValues / 2, (size_t)w * 2); data->nValues = MINIMUM(data->nValues, MAX_METER_GRAPHDATA_VALUES); @@ -308,10 +308,8 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { 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; - } + if (nValues < 1) + return; const Machine* host = this->host; if (!timercmp(&host->realtime, &(data->time), <)) { @@ -325,6 +323,13 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { data->values[nValues - 1] = sumPositiveValues(this->values, this->curItems); } + if (w <= 0) + return; + if ((size_t)w > nValues / 2) { + x += w - nValues / 2; + w = nValues / 2; + } + const char* const* GraphMeterMode_dots; int GraphMeterMode_pixPerRow; #ifdef HAVE_LIBNCURSESW