PDCurses
PDCurses copied to clipboard
wresize doesn't return ERR if the window size requested is too big
Hi there,
I've been fixing my implementation of resize for my game and noticed that if you call wresize
with a window that doesn't fit within SP->lines
and SP->cols
it doesn't return ERR. This was a problem for me because my program would call wtouchwin
immediately after and segfault.
I took a look at newwin
and it has protection against this case, but wresize
does not.
https://github.com/wmcbrine/PDCurses/blob/5c62af03e9a05e3a3ae8c8354c1234b772dcf4b0/pdcurses/window.c#L276-L277
For my program I wrote a dumb little wrapper around wresize that performs the check:
int
wresize_wrapper(WINDOW *win, int nlines, int ncols) noexcept
{
// THIS WAS COPIED FROM newwin
if (!SP || win->_begy + nlines > SP->lines || win->_begx + ncols > SP->cols)
return ERR;
return ::wresize(win, nlines, ncols);
}
- Do you agree that not having this check is a problem?
- Would you be open to having this fixed? Thank you so much for your time.
It should be fixed, but this is probably not the way. There's a difference in the way PDCurses and ncurses handle windows that don't fit the screen, and we probably should do it their way for maximum portability, and that's a deeper change. See e.g. issue #85 .
I think the only difference is that in ncurses, newwin()
can create an oversized window that goes off the right or bottom edge of the screen. You can't set begx
or begy
to a negative value to get a window that goes off the left or top edges. Am I missing other differences?
The ncurses behavior is somewhat inconsistent, in that while you can create a window going off those two edges, you can't move a window there. And I don't see why, if you can have a window run over one edge, you shouldn't be able to have it run over the other two.
The only way I can think of to get a partially off-screen window (as opposed to a pad) in PDCurses is to resize the screen such that the window goes off the right or bottom edges. (It works that way in ncurses as well.)
The only way I can think of to get a partially off-screen window (as opposed to a pad) in PDCurses is to resize the screen such that the window goes off the right or bottom edges. (It works that way in ncurses as well.)
Yeah I was reading up on that earlier, seems unfortunate but I understand if you want to leave this compatibility with ncurses in.
However I do think it crashing is problematic.