Subject: libcurses border() leads to segfault
To: None <current-users@netbsd.org>
From: Neil Ludban <nludban@columbus.rr.com>
List: current-users
Date: 10/23/2005 11:37:44
I've got a small libcurses test program that dumps core when linked with
electric fence:
% cat test-border.c
#include <curses.h>
#include <stdlib.h>
#include <unistd.h>
int
main()
{
initscr();
border(0,0,0,0,0,0,0,0);
refresh();
sleep(5);
endwin();
exit(0);
}
% gcc -Wall -g test-border.c -lcurses
% ./a.out
<displays a nice border for 5 seconds>
% gcc -Wall -g test-border.c -lcurses -L/usr/local/lib -lefence
% gdb a.out
(gdb) run
Program received signal SIGSEGV, Segmentation fault.
0x4806da3d in doupdate () from /usr/lib/libcurses.so.5
(gdb) bt
#0 0x4806da3d in doupdate () from /usr/lib/libcurses.so.5
#1 0x4806d09a in doupdate () from /usr/lib/libcurses.so.5
#2 0x4806cd93 in wrefresh () from /usr/lib/libcurses.so.5
#3 0x4806c823 in refresh () from /usr/lib/libcurses.so.5
#4 0x8048e50 in main () at test-border.c:10
#5 0x8048ae4 in ___start ()
It crashes under both 2.0_BETA and 3.99.5. I've done some initial
debugging on the 2.0 box. At the end of border.c:
/* Corners */
if (!(win->maxx == LINES && win->maxy == COLS &&
^^^^^^^^^^^^^ ^^^^^^^^^^^^
(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
fp[0].ch = (wchar_t) topleft & __CHARTEXT;
fp[0].bch = win->bch;
fp[0].attr = (attr_t) topleft & __ATTRIBUTES;
fp[0].battr = win->battr;
fp[endx].ch = (wchar_t) topright & __CHARTEXT;
fp[endx].bch = win->bch;
fp[endx].attr = (attr_t) topright & __ATTRIBUTES;
fp[endx].battr = win->battr;
lp[0].ch = (wchar_t) botleft & __CHARTEXT;
lp[0].bch = win->bch;
lp[0].attr = (attr_t) botleft & __ATTRIBUTES;
lp[0].battr = win->battr;
// lp[endx].ch = (wchar_t) botright & __CHARTEXT;
// lp[endx].bch = win->bch;
// lp[endx].attr = (attr_t) botright & __ATTRIBUTES;
// lp[endx].battr = win->battr;
}
__touchwin(win);
return (OK);
The test looks wrong, maxy == LINES && maxx == COLS would be more
intuitive. This change didn't make any difference.
Commenting out the last 4 lines allows the program to run under
electric fence, with and without the previous change.
Any other suggestions before I send-pr?
-Neil