>Number: 6223
>Category: lib
>Synopsis: Curses subwin() SEGVs when used on widows smaller than stdscr.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people (Library Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 1 11:50:01 1998
>Last-Modified:
>Originator: Mike Kelly
>Organization:
CSU Chico
>Release: NetBSD-1.3.2 (GENERIC) <NetBSD-current source date>
>Environment:
System: NetBSD ratbert 1.3.2 NetBSD 1.3.2 (GENERIC) #0: Fri May 15 12:41:16 CDT 1998 scottr@beech:/usr/src/sys/arch/hp300/compile/GENERIC hp300
>Description:
When a user creates a subwin() in the standard window (stdscr), it works fine.
However, when the subwin() function is called to make a sub window in a window
smaller than the termianl screen (stdscr), a SIGSEGV is recieved. Since a sub
window shares the memory space of the parent window as much as possible,
subwin() calls __set_subwin() to figure out which parts are shared.
__set_subwin() does not correctly calculate the location of the screen immage
that is to be shared. Speciffically, it does not subtract the offset of the
parent window from the edge of the screen.
>How-To-Repeat:
#include <curses.h>
int
main()
{
WINDOW *win;
initscr();
win = newwin(12, 12, 10,10);
subwin(win, 10, 10, 11,11);
endwin();
return 0;
}
>Fix:
Apply the following patch to src/lib/libcurses/newwin.c:
144,145c144,145
< olp = orig->lines[i + win->begy];
< lp->line = &olp->line[win->begx];
---
> olp = orig->lines[i + win->begy - orig->begy];
> lp->line = &olp->line[win->begx - orig->begx];
NOTE: subwin() is not the only function that calls __set_subwin(). I did not
explore mvwin(), refresh() or any other function that may call __set_subwin().
While I have experenced no problems with refresh() on my sub window, it may
be possible (though unlikely) that these functions will break in subtle ways
when this patch is applied.
>Audit-Trail:
>Unformatted: