[net.bugs] Curses bug

bobvan (09/27/82)

I've tracked down a bug in curses on our 4.1BSD system, but I suspect
that it is present in all curseses.  It manifests itself as garbage
characters on your screen and is agrivated when using windows with
the left edge between column 0 and 7.  Here is a short C program that
shows the problem.  Note that if your terminal can't do CR without LF,
curses won't go for (and botch) the optimization.  It is known to fail
on VT-100's (sounds like a cigarette).

	#include	<curses.h>
	main()
	{
		WINDOW *w;

		initscr();
		w = newwin(3, 4, 4, 3);
		box(w, ':', '.');
		wrefresh();
		endwin();
	}

I have a fix, but make no claims about the quality.  With the fix
installed, the bug goes away.  However, it contains a goto and the code
around there is fairly crufty, so I don't want to make any guarantees.
Perhaps a Berkeley guru would like to suggest something cleaner?
A diff -c of the fix follows:

*** /usr/src/lib/libcurses/cr_put.c	Thu Mar  5 22:56:56 1981
--- cr_put.c	Thu Sep 23 13:47:52 1982
***************
*** 255,260
  			if (plodflg)	/* avoid a complex calculation */
  				plodcnt--;
  			else {
  				c = _win->_y[outline-_win->_begy][outcol-_win->_begx];
  				if ((c&_STANDOUT) == (curscr->_flags&_STANDOUT))
  					putchar(c);

--- 255,262 -----
  			if (plodflg)	/* avoid a complex calculation */
  				plodcnt--;
  			else {
+ 				if (outcol < _win->_begx) /* RAV hack fix */
+ 					goto nondes;
  				c = _win->_y[outline-_win->_begy][outcol-_win->_begx];
  				if ((c&_STANDOUT) == (curscr->_flags&_STANDOUT))
  					putchar(c);
------------------------------------

				Bob Van Valzah
				(...!decvax!ittvax!tpdcvax!bobvan)

laman@sdcsvax.UUCP (Mike Laman) (11/12/83)

There is a bug in wdeleteln().  This bug is in the curses library distributed
over net.sources, and in the 4.2 BSD distribution (that sdcsvax received
at least).

Even though the last line of the window gets cleared internally, its "refresh"
image may not.  The fix is simple.  Add the following two lines to the end
of the wdeleteln() routine.

	win->_firstch[win->_maxy-1] = 0;
	win->_lastch[win->_maxy-1] = win->_maxx - 1;

Now wrefresh() will look at the entire line.

I have enclosed a little program that will show you if you have the bug.  Just
compile it with you curses library (termlib too) and run it.

#include	<curses.h>

main() {
	register i;

	initscr();
	mvaddstr(0, 20, "This program will delete line #5 after");
	mvaddstr(1, 20, "writing the line number for each line.");
	for(i = 0; i < LINES; ++i)
		mvprintw(i, 0, "Line #%d", i);
	refresh();
	addstr("     You have the bug if the BOTTOM line is not COMPLETELY blank!");
	move(5, 0);
	deleteln();
	move(LINES - 3, 0);
	refresh();
	endwin();
}

			Mike Laman
			UUCP: {ucbvax,philabs,sdccsu3,sdcsla}!sdcsvax!laman

laman@sdcsvax.UUCP (Mike Laman) (11/14/83)

I strongly suspect this fix didn't get out.  We got device full error messages
just when I posted this earlier this week.  Sorry, if you've saw the original.

There is a bug in wdeleteln().  This bug is in the curses library distributed
over net.sources, and in the 4.2 BSD distribution (that sdcsvax received
at least).

Even though the last line of the window gets cleared internally, its "refresh"
image may not.  The fix is simple.  Add the following two lines to the end
of the wdeleteln() routine.

	win->_firstch[win->_maxy-1] = 0;
	win->_lastch[win->_maxy-1] = win->_maxx - 1;

Now wrefresh() will look at the entire line.

I have enclosed a little program that will show you if you have the bug.  Just
compile it with you curses library (termlib too) and run it.

#include	<curses.h>

main() {
	register i;

	initscr();
	mvaddstr(0, 20, "This program will delete line #5 after");
	mvaddstr(1, 20, "writing the line number for each line.");
	for(i = 0; i < LINES; ++i)
		mvprintw(i, 0, "Line #%d", i);
	refresh();
	addstr("     You have the bug if the BOTTOM line is not COMPLETELY blank!");
	move(5, 0);
	deleteln();
	move(LINES - 3, 0);
	refresh();
	endwin();
}

			Mike Laman
			UUCP: {ucbvax,philabs,sdccsu3,sdcsla}!sdcsvax!laman