summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2023-10-12 00:46:48 +0800
committerBenBE <BenBE@geshi.org>2023-10-26 22:49:22 +0200
commit4ef3e1f1bb014cec9504e5247d0a0ad999597b9d (patch)
tree69ec078f4583837b9d88c4e14aafa9eec0e9139c /Meter.c
parent49bc76d4796b3b0c03fb0a339af40e6751acedd3 (diff)
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 <explorer09@gmail.com>
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/Meter.c b/Meter.c
index bb137aad..752c3ccd 100644
--- a/Meter.c
+++ b/Meter.c
@@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "Meter.h"
#include <assert.h>
+#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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);
@@ -307,11 +307,10 @@ 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 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 +324,14 @@ 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

© 2014-2024 Faster IT GmbH | imprint | privacy policy