summaryrefslogtreecommitdiffstats
path: root/Meter.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2011-08-26 20:55:09 +0000
committerHisham Muhammad <hisham@gobolinux.org>2011-08-26 20:55:09 +0000
commit717758409e24b42dba8fbf1ac77c6fdf524efc12 (patch)
treec594978a7f0744685b766dbd5a9c8cb60d301bed /Meter.c
parentaa167adb90704e09726553a21bf3385991e958bf (diff)
Fix segfault in BarMeterMode_draw() for small terminal widths
Diffstat (limited to 'Meter.c')
-rw-r--r--Meter.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Meter.c b/Meter.c
index 6947d9b3..57862364 100644
--- a/Meter.c
+++ b/Meter.c
@@ -264,13 +264,19 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
w--;
x++;
- char bar[w];
+
+ if (w < 1) {
+ attrset(CRT_colors[RESET_COLOR]);
+ return;
+ }
+ char bar[w + 1];
int blockSizes[10];
for (int i = 0; i < w; i++)
bar[i] = ' ';
- sprintf(bar + (w-strlen(buffer)), "%s", buffer);
+ const size_t barOffset = w - MIN(strlen(buffer), w);
+ snprintf(bar + barOffset, w - barOffset + 1, "%s", buffer);
// First draw in the bar[] buffer...
double total = 0.0;

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