Bill-Gray/PDCursesMod

subwin with zero ncols creates one char smaller window than on ncurses

okbob opened this issue · 4 comments

okbob commented

I use subwindows created by call of subwin(parentwin, 1, 0, 0, 0). It should to create one row subwindows with same width like parent window. It is works on ncurses without any problems. Unfortunately pdcurses makes subwindow one character smaller.

I wrote test case:

#include <curses.h>

int
main()
{
	WINDOW *win;
	int		stdscr_rows, stdscr_cols;
	int		subwin_rows, subwin_cols;

	initscr();

	getmaxyx(stdscr, stdscr_rows, stdscr_cols);

	win = subwin(stdscr, 1, 0, 0, 0);

	getmaxyx(win, subwin_rows, subwin_cols);

	delwin(win);

	endwin();

#ifdef PDCURSES

	fprintf(stderr, "**** pdcurses ****\n");

#else

	fprintf(stderr, "**** ncurses ****\n");

#endif

	fprintf(stderr, "stdscr: %d %d\n", stdscr_rows, stdscr_cols);
	fprintf(stderr, "subwin: %d %d\n", subwin_rows, subwin_cols);
}

result:

[pavel@localhost PDCursesMod]$ gcc test-ncurse2.c -I/usr/local/include/pdcurses -DPDC_WIDE=Y -DPDC_FORCE_UTF8=Y -L/usr/local/lib -lpdcurses 
[pavel@localhost PDCursesMod]$ ./a.out 
**** pdcurses ****
stdscr: 53 134
subwin: 1 133
[pavel@localhost PDCursesMod]$ gcc test-ncurse2.c -lncurses
[pavel@localhost PDCursesMod]$ ./a.out 
**** ncurses ****
stdscr: 53 134
subwin: 1 134

I'm getting the same behavior here, with both PDCursesMod and @wmcbrine's PDCurses. I've modified your code to allow setting of the rows/columns. Running

./iss265 1

will replicate your results. Run without command-line arguments, you'll see that this off-by-one issue affects height as well as width. We are setting the number of rows/columns to one minus the containing window size, and have done so since the first version of this function was written 22 years ago.

However, if you look at the range checking for columns/heights in the subwin() function, it's perfectly fine with the subwindow being the same size as the containing window. Run (in your case) ./iss265 53 143, and you'll get the desired subwindow. Make it one larger in either direction, and it'll say Failed to allocate window. All of which suggests to me that both -1s should be removed.

okbob commented

Pushed the (very minor) fix required for this. I admit to (mild) concern that somebody was actually relying on this misbehavior... I'm really puzzled that it's slipped past us for 22 years!

okbob commented