summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorExplorer09 <explorer09@gmail.com>2023-10-10 20:17:48 +0800
committerBenBE <BenBE@geshi.org>2023-10-10 21:57:39 +0200
commit74b28849c4ee7234aa6018667ff6c8c9a6b41273 (patch)
tree40983a30b0d9cea958116133c1444ce8376e4ff4 /Meter.c
parent44cace2664dd2d555de1e02c2f7a626186fbfbe7 (diff)
Let GraphMeterMode_draw() return early when the meter is too narrow...
...to draw even a single record of the graph. This makes the code more robust by checking (w <= 0) explicitly. Also avoids unnecessary reallocations of the GraphData buffer. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/Meter.c b/Meter.c
index 5b2784dc..df3412b0 100644
--- a/Meter.c
+++ b/Meter.c
@@ -289,10 +289,18 @@ static const char* const GraphMeterMode_dotsAscii[] = {
};
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
+ const char* caption = Meter_getCaption(this);
+ attrset(CRT_colors[METER_TEXT]);
+ const int captionLen = 3;
+ mvaddnstr(y, x, caption, captionLen);
+ x += captionLen;
+ w -= captionLen;
+ if (w <= 0)
+ return;
+
const Machine* host = this->host;
GraphData* data = &this->drawData;
- assert(w > 0);
if ((size_t)w * 2 > data->nValues) {
size_t oldNValues = data->nValues;
data->nValues = MAXIMUM(oldNValues + (oldNValues / 2), (size_t)w * 2);
@@ -315,13 +323,6 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
GraphMeterMode_pixPerRow = PIXPERROW_ASCII;
}
- const char* caption = Meter_getCaption(this);
- attrset(CRT_colors[METER_TEXT]);
- int captionLen = 3;
- mvaddnstr(y, x, caption, captionLen);
- x += captionLen;
- w -= captionLen;
-
if (!timercmp(&host->realtime, &(data->time), <)) {
int globalDelay = this->host->settings->delay;
struct timeval delay = { .tv_sec = globalDelay / 10, .tv_usec = (globalDelay % 10) * 100000L };

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