Subject: Re: lib/36702: vi crashes on window resizes due to bug in curses
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Julian Coleman <jdc@coris.org.uk>
List: netbsd-bugs
Date: 08/02/2007 13:35:02
The following reply was made to PR lib/36702; it has been noted by GNATS.

From: Julian Coleman <jdc@coris.org.uk>
To: gnats-bugs@NetBSD.org, erh@swapsimple.com
Cc: 
Subject: Re: lib/36702: vi crashes on window resizes due to bug in curses
Date: Thu, 2 Aug 2007 14:33:45 +0100

 I think I know the problem - it looks like LINES and COLS being changed
 between wresize() calls in tstp.c:__restartwin().  Can you try the attached
 patch, please?
 
 Thanks,
 
 J
 
   - - 8< - - - - - - - - - - - - - Cut here - - - - - - - - - - - - - >8 - -
 --- /usr/src/lib/libcurses/resize.c	2007-05-29 07:07:54.000000000 +0100
 +++ resize.c	2007-08-02 14:21:26.000000000 +0100
 @@ -64,6 +64,10 @@
  	if (win == NULL)
  		return ERR;
  
 +#ifdef	DEBUG
 +	__CTRACE(__CTRACE_WINDOW, "wresize: (%p, %d, %d)\n",
 +	    win, nlines, ncols);
 +#endif
  	nlines = req_nlines;
  	ncols = req_ncols;
  	if (win->orig == NULL) {
 @@ -94,6 +98,13 @@
  	win->reqy = req_nlines;
  	win->reqx = req_ncols;
  
 +	/* If someone resized curscr, we must also resize __virtscr */
 +	if (win == curscr) {
 +		if ((__resizewin(__virtscr, nlines, ncols)) == ERR)
 +			return ERR;
 +		__virtscr->reqy = req_nlines;
 +		__virtscr->reqx = req_ncols;
 +	}
  	return OK;
  }
  
 --- /usr/src/lib/libcurses/tstp.c	2007-01-21 13:25:36.000000000 +0000
 +++ tstp.c	2007-08-02 14:22:32.000000000 +0100
 @@ -253,6 +253,7 @@
  __restartwin(void)
  {
  	struct winsize win;
 +	int lines, cols;
  
  #ifdef DEBUG
  	__CTRACE(__CTRACE_MISC, "__restartwin\n");
 @@ -281,12 +282,18 @@
  			_cursesi_screen->resized = 1;
  		}
  	}
 -	if (curscr->maxy != LINES || curscr->maxx != COLS)
 -		wresize(curscr, LINES, COLS);
 -	if (stdscr->maxy != LINES || stdscr->maxx != COLS)
 -		wresize(stdscr, LINES, COLS);
 -	if (__virtscr->maxy != LINES || __virtscr->maxx != COLS)
 -		wresize(__virtscr, LINES, COLS);
 +	/*
 +	 * We need to make local copies of LINES and COLS, otherwise we
 +	 * could lose if they are changed between wresize() calls.
 +	 */
 +	lines = LINES;
 +	cols = COLS;
 +	if (curscr->maxy != lines || curscr->maxx != cols)
 +		wresize(curscr, lines, cols);
 +	if (stdscr->maxy != lines || stdscr->maxx != cols)
 +		wresize(stdscr, lines, cols);
 +	if (__virtscr->maxy != lines || __virtscr->maxx != cols)
 +		wresize(__virtscr, lines, cols);
  
  	/* save the new "default" terminal state */
  	(void) tcgetattr(fileno(_cursesi_screen->infd),
   - - 8< - - - - - - - - - - - - - Cut here - - - - - - - - - - - - - >8 - -
 
 -- 
   My other computer also runs NetBSD    /        Sailing at Newbiggin
         http://www.netbsd.org/        /   http://www.newbigginsailingclub.org/