Subject: Re: bin/12304: top(1) output garbled if header line(s) wider than terminal
To: None <mkb@moghedien.mayn.de>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-bugs
Date: 03/01/2001 12:33:17
mkb@mukappabeta.de wrote:

> 
> >Number:         12304
> >Category:       bin
> >Synopsis:       top(1) output garbled if header line(s) wider than terminal
> 
> >Description:
> 
> if one of the top header info lines is wider than the terminal (80 characters
> here), the title header line of the processes list becomes interspersed
> with the first processes line, resulting in visually garbled output:
> 
> 
> Memory: 8720K Act, 1836K Inact, 244K Wired, 5248K Free, 2840K Swap, 94M Swap fre
> e
> 
>   PID USERNAME P55 NICE   SIZE   RES run       TI42 30.03% 30.03U COMMAND

In -current, "Swap" has been changed to "Swp" which is still technically
two characters short, but should cover most cases.  I'll at least get
that pulled up to the 1.5 branch...

This patch should at least fix the overrun problem for the initial
memory status line and all line updates.  Does it work ok for you?

Index: display.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/top/display.c,v
retrieving revision 1.4
diff -d -p -u -r1.4 display.c
--- display.c	2000/11/02 15:28:51	1.4
+++ display.c	2001/03/01 01:32:21
@@ -530,6 +530,9 @@ int *stats;
 
     /* format and print the memory summary */
     summary_format(memory_buffer, stats, memory_names);
+    /* trim the string to fit on one line */
+    if (strlen(memory_buffer) + sizeof("Memory: ") - 1 > screen_width)
+	memory_buffer[screen_width - sizeof("Memory: ") + 1] = '\0';
     fputs(memory_buffer, stdout);
 }
 
@@ -1124,7 +1127,10 @@ int line;
 	/* update working column and screen buffer pointer */
 	newcol++;
 	old++;
-	    
+
+	/* don't overrun end of line */
+	if (newcol >= display_width)
+		break;
     } while (ch != '\0');
 
     /* zero out the rest of the line buffer -- MUST BE DONE! */


Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD CDs, Support and Service:    http://www.wasabisystems.com/