diff options
author | Explorer09 <explorer09@gmail.com> | 2023-10-10 20:17:48 +0800 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-10-10 21:57:39 +0200 |
commit | 74b28849c4ee7234aa6018667ff6c8c9a6b41273 (patch) | |
tree | 40983a30b0d9cea958116133c1444ce8376e4ff4 /Meter.c | |
parent | 44cace2664dd2d555de1e02c2f7a626186fbfbe7 (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.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -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 }; |