Bug in curses package

per at chalmers.UUCP per at chalmers.UUCP
Thu May 17 22:07:56 AEST 1984


Subject:
	Curses package sometimes dump core.
Index:
	usr.lib/libcurses 4.2BSD

Description:
	Screen oriented programs that worked on terminals like vt100,
	caused 'segmentation fault' when run on facit 4440. (Swedish
	terminal, 72 lines by 80 columns). 

	The problem was caused by a loop like:
	    while (*cp++ == *dp++)
		;
	(Now I start guessing)
	The reason this hasn't been detected before is that the curses
	package does a lot of calloc()/free().
	The amount of space used by 'curscr' and 'stdscr', allocated
	by initscr(), is less than what is used during other
	initialiations. The result is that "above" 'curscr' and
	'stdscr' there is memory that no longer is initialized to 0.
	But this is only true if 'stdscr' and 'curscr' are small
	enough. That isn't the case when the screen is 72x80.

Repeat-By:
	/* start of test.c */
	#include <curses.h>

	#define	FMT	"libcurses test, line %d"

	main(argc, argv)
	{
	    register i;

	    /* simulate 72x80 screen (facit 4440) */
	    LINES = 72;
	    COLS = 80;

	    initscr();

	    for (i = 0; i < 15; i++)
		mvprintw(i, 5, FMT, i+1);

	    move(20,1);
	    refresh();
	    endwin();
	}
	/* end of test.c */

	compile with:
		cc test.c -lcurses -ltermcap
	run by:
		a.out
Fix:

	Diff listing (edited) follows. Line numbers are not correct
	due to other minor changes.

	*** refresh.c.old	Wed May 16 23:48:53 1984
	--- refresh.c.new	Sat May 12 00:17:46 1984
	***************
	*** 235,243
				lx = wx + win->_begx;
			}
			else if (wx < lch)
	! 			while (*nsp == *csp) {
	  				nsp++;
	  				if (!curwin)
						csp++;
					++wx;
				}

	--- 240,248 -----
				lx = wx + win->_begx;
			}
			else if (wx < lch)
	! 			while (*nsp == *csp && wx < lch) {
					nsp++;
					if (!curwin)
						csp++;
					++wx;
				}

	    Per Westerlund
	    Dept of Comp Sci
	    Chalmers U of Tech
	    S-412 96 Gothenburg
	    SWEDEN



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