Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wresize doesn't return ERR if the window size requested is too big #162

Open
bjadamson opened this issue Mar 5, 2024 · 3 comments
Open

Comments

@bjadamson
Copy link

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.

PDCurses/pdcurses/window.c

Lines 276 to 277 in 5c62af0

if (!SP || begy + nlines > SP->lines || begx + ncols > SP->cols)
return (WINDOW *)NULL;

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);
}
  1. Do you agree that not having this check is a problem?
  2. Would you be open to having this fixed?
    Thank you so much for your time.
@bjadamson bjadamson changed the title Adding an additional check inside wresize wresize doesn't return ERR if the window size requested is too big Mar 5, 2024
@wmcbrine
Copy link
Owner

wmcbrine commented Mar 7, 2024

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 .

@Bill-Gray
Copy link
Contributor

Bill-Gray commented Mar 7, 2024

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.)

@bjadamson
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants