bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ncurses can crash when resizing one of several screens


From: Thomas Dickey
Subject: Re: Ncurses can crash when resizing one of several screens
Date: Sat, 03 Jul 2010 15:07:00 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

On Sat, Jul 03, 2010 at 01:05:29AM -0700, Scott Dolim wrote:
> Hello,
> 
> I'm using ncurses in a possibly unusual way: I create several SCREENs
> on a set of tty's which are communicating with separate telnet
> sessions via sockets on their pty sides.  Therefore, they get a
> SIGWINCH when the telnet client's window (xterm) is resized.
> 
> The problem I'm finding is that when one of the SCREENs is resized,
> then a subsequent doupdate() on a separate SCREEN can segfault.  It
> turns out that the WINDOWs in the other SCREENs have all been adjusted
> to the new size of the resized SCREEN.   Now the WINDOW's size can be

It's more complicated than that.

I'm puzzled why all of your screens would be getting the same size.

When ncurses sees a SIGWINCH, it doesn't know which SCREEN it applies to - the
signal doesn't come with information to tell that.  So ncurses sets a flag in
each SCREEN to tell the library to ask for the current screensize at the next
opportunity.  That might happen after the application has called set_curterm,
which would switch SCREENs.

While it cannot tell which SCREEN is affected, each SCREEN holds a file
descriptor, which is supposed to allow ncurses to query the corresponding
window size.  Normally that's an output (stdout or stderr), though it's
possible it could be "any" descriptor by calling setupterm with suitable
parameters.

> out of sync with its own SCREEN.  The crash actually occurs in
> _nc_hash_map, when the line index i goes past the end of the window's
> line array if it is smaller than expected.
> 
> This is happening because the functions increase_size() and
> decrease_size() in resizeterm.c walk the global window list using "for
> (each_window(wp))", but they do not check if each window belongs to
> the current screen before they apply the adjustment for the one screen
> that got resized.
> 
> I've made a quick fix that seems to fix the problem.  The attached
> diff shows the change.
> 
> This is from ncurses 5.7.  My platform is Arch Linux.

thanks... But in current code, the window-list is per-screen,
so that's no longer needed.

> --- ncurses-5.7/ncurses/base/resizeterm.c     2008-06-07 06:58:40.000000000 
> -0700
> +++ resizeterm.c      2010-07-03 00:12:25.691919596 -0700
> @@ -252,6 +252,8 @@
>       TR(TRACE_UPDATE, ("decreasing size of windows to %dx%d, depth=%d",
>                         ToLines, ToCols, depth));
>       for (each_window(wp)) {
> +         if (wp->screen != SP)
> +             continue;
>           WINDOW *win = &(wp->win);
>  
>           if (!(win->_flags & _ISPAD)) {
> @@ -286,6 +288,8 @@
>       TR(TRACE_UPDATE, ("increasing size of windows to %dx%d, depth=%d",
>                         ToLines, ToCols, depth));
>       for (each_window(wp)) {
> +         if (wp->screen != SP)
> +             continue;
>           WINDOW *win = &(wp->win);
>  
>           if (!(win->_flags & _ISPAD)) {

-- 
Thomas E. Dickey <address@hidden>
http://invisible-island.net
ftp://invisible-island.net

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]