public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-x86 commit in sys-process/htop/files: htop-0.9-small-width.patch
@ 2011-08-26 21:37 Sebastian Pipping (sping)
  0 siblings, 0 replies; only message in thread
From: Sebastian Pipping (sping) @ 2011-08-26 21:37 UTC (permalink / raw
  To: gentoo-commits

sping       11/08/26 21:37:18

  Added:                htop-0.9-small-width.patch
  Log:
  sys-process/htop: Integrate post-0.9 bugfix patch
  
  (Portage version: 2.1.10.11/cvs/Linux x86_64)

Revision  Changes    Path
1.1                  sys-process/htop/files/htop-0.9-small-width.patch

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-process/htop/files/htop-0.9-small-width.patch?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-process/htop/files/htop-0.9-small-width.patch?rev=1.1&content-type=text/plain

Index: htop-0.9-small-width.patch
===================================================================
From 17d258ff0a216dd87655c8e93d065e5e6c504f42 Mon Sep 17 00:00:00 2001
From: Sebastian Pipping <sebastian@pipping.org>
Date: Mon, 1 Aug 2011 02:51:24 +0200
Subject: [PATCH 3/3] Fix segfault in BarMeterMode_draw() for small terminal
 widths

Segfault can be triggered by running "COLUMNS=1 ./htop"
For me, COLUMNS=40 was the first that would not crash.
---
 ChangeLog |    2 ++
 Meter.c   |   11 +++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/Meter.c b/Meter.c
index 6947d9b..408b981 100644
--- a/Meter.c
+++ b/Meter.c
@@ -264,13 +265,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 bar_offset = w - MIN(strlen(buffer), w);
+   snprintf(bar + bar_offset, w - bar_offset + 1, "%s", buffer);
 
    // First draw in the bar[] buffer...
    double total = 0.0;
-- 
1.7.6







^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-26 21:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-26 21:37 [gentoo-commits] gentoo-x86 commit in sys-process/htop/files: htop-0.9-small-width.patch Sebastian Pipping (sping)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox