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

Fix crashes with windows overlapping right and bottom edges of screen #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pdcurses/refresh.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int wnoutrefresh(WINDOW *win)
begy = win->_begy;
begx = win->_begx;

for (i = 0, j = begy; i < win->_maxy; i++, j++)
for (i = 0, j = begy; i < win->_maxy && j < curscr->_maxy; i++, j++)
{
if (win->_firstch[i] != _NO_CHANGE)
{
Expand All @@ -88,6 +88,9 @@ int wnoutrefresh(WINDOW *win)
int first = win->_firstch[i]; /* first changed */
int last = win->_lastch[i]; /* last changed */

if( last > curscr->_maxx - begx - 1) /* don't run off right-hand */
last = curscr->_maxx - begx - 1; /* edge of screen */

/* ignore areas on the outside that are marked as changed,
but really aren't */

Expand Down Expand Up @@ -128,6 +131,10 @@ int wnoutrefresh(WINDOW *win)
{
curscr->_cury = win->_cury + begy;
curscr->_curx = win->_curx + begx;
if( win->_cury >= win->_maxy)
win->_cury = win->_maxy - 1;
if( win->_curx >= win->_maxx)
win->_curx = win->_maxx - 1;
}

return OK;
Expand Down
5 changes: 2 additions & 3 deletions pdcurses/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ WINDOW *newwin(int nlines, int ncols, int begy, int begx)
if (!ncols)
ncols = COLS - begx;

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

win = PDC_makenew(nlines, ncols, begy, begx);
Expand Down Expand Up @@ -314,8 +314,7 @@ int mvwin(WINDOW *win, int y, int x)
{
PDC_LOG(("mvwin() - called\n"));

if (!win || (y + win->_maxy > LINES || y < 0)
|| (x + win->_maxx > COLS || x < 0))
if (!win || y < 0 || x < 0)
return ERR;

win->_begy = y;
Expand Down