summaryrefslogtreecommitdiff
path: root/extra/htop/fix-segfault-small-terminal.patch
diff options
context:
space:
mode:
Diffstat (limited to 'extra/htop/fix-segfault-small-terminal.patch')
-rw-r--r--extra/htop/fix-segfault-small-terminal.patch24
1 files changed, 24 insertions, 0 deletions
diff --git a/extra/htop/fix-segfault-small-terminal.patch b/extra/htop/fix-segfault-small-terminal.patch
new file mode 100644
index 000000000..c55146492
--- /dev/null
+++ b/extra/htop/fix-segfault-small-terminal.patch
@@ -0,0 +1,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;