Subject: lib/6223: Curses subwin() SEGVs
To: None <email@example.com>
From: None <firstname.lastname@example.org>
Date: 10/01/1998 11:35:57
>Synopsis: Curses subwin() SEGVs when used on widows smaller than stdscr.
>Responsible: lib-bug-people (Library Bug People)
>Arrival-Date: Thu Oct 1 11:50:01 1998
>Originator: Mike Kelly
>Release: NetBSD-1.3.2 (GENERIC) <NetBSD-current source date>
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
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.
win = newwin(12, 12, 10,10);
subwin(win, 10, 10, 11,11);
Apply the following patch to src/lib/libcurses/newwin.c:
< 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.