summaryrefslogtreecommitdiff
path: root/extra/htop/fix-segfault-small-terminal.patch
blob: c55146492dc869e22d02f68bd21ccfc4f212822a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--- trunk/Meter.c	2011/08/26 20:52:35	229
+++ trunk/Meter.c	2011/08/26 20:55:09	230
@@ -264,13 +264,19 @@
    
    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;