Bug in curses package

Mike Laman laman at sdcsvax.UUCP
Tue May 22 10:04:16 AEST 1984


Yes, that is a bug.  I posted the very same fix a good number of months ago.
On systems that it doesn't dump core, it does MUCH more looking than is needed!
The problem is that it is supposed to walk down JUST the ONE line; instead
it walks down the entire window.  Think about it and you will see A LOT of
time can be wasted.

Since this fix is being posted I thought I would repost the set of fixes I
put over a good while ago.  My apologies to those that have seen these before.

Beginning of previous bug fix list message posted earlier...

Some one asked for bug fixes to 4.1 curses.  All the following should be
relevent.  I am posting this synopsis to answer his request and since
San Diego was cut off for about a month, others may find it interesting
(otherwise I would have just replied to him).  I apologize to those in the
San Diego area who has seen parts of this for the fourth time.  Strange
though, the request is from the San Diego area....

I have included two messages that I sent out on bug fixes.  They are at the
end.  Several other fixes are as follows:

1. Add touchwin(win); to the end of winsertln().
2. If your loop in wgetstr() has a semicolon on the end which blocks off the
   pointer incrmentation as implied by the indentation style, reomve that
   semi colon:

   while(some ugly god awful expression);
	++str;			        ^
				        |
				        |
				    Dumb huh
3. If your first loop in wdeleteln() looks like:

				:
				:
				:
	for (y = win->_cury; y < win->_maxy - 2; y++) {
				:
				:
				:

   This doesn't get the last line of the given window.  Change it to the
   following:

				:
				:
				:
	for (y = win->_cury; y < win->_maxy - 1; y++) {
				:
				:
				:

Here are the other two fixes which I have previously posted on the network.

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();
}

And the other:

    The following bug is in the curses library distributed over net.sources,
and in the 4.2 BSD distribution (that sdcsvax received at least).

    The bug is in makech() (in refresh.c).  makech() gets called to give
output for the given LINE (hint hint).  It is interesting that this bug
managed to get out.  Here is the offending code (the simple fix follows).

			:
			:
			:
		else if (wx < lch)
			while (*nsp == *csp) {
				nsp++;
				if (!curwin)
					csp++;
				++wx;
			}
		else
			:
			:
			:

I wrote a program that added '*' to (0, 0) on stdscr then a refresh().
wx ended up with a value of over 3000!  That loop walked down the line
and the next, ... (all the way down the window!).  The following code
is the fix.  Notice that the ++wx looks just perfect.  It really makes one
think "they" thought of it, but merely forgot to add the test.

			:
			:
			:
		else if (wx < lch)
			while (*nsp == *csp && wx <= lch) {
				nsp++;
				if (!curwin)
					csp++;
				++wx;
			}
		else
			:
			:
			:

--- End of previous message


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



More information about the Comp.bugs.4bsd.ucb-fixes mailing list