From a2a61a486e9682efcfc4b98bcedca03f92f3ef76 Mon Sep 17 00:00:00 2001 From: Bill-Gray Date: Thu, 18 Jul 2024 07:12:43 -0400 Subject: [PATCH 1/2] Windows extending beyond the right and bottom edges of curscr no longer segfault; wnoutrefresh() clips to those boundaries. --- pdcurses/refresh.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pdcurses/refresh.c b/pdcurses/refresh.c index 5b36d0fa..aa0d4a69 100644 --- a/pdcurses/refresh.c +++ b/pdcurses/refresh.c @@ -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) { @@ -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 */ @@ -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; From 6ba6df38f7f22f99a7225a6d6dbca0c66ee2913e Mon Sep 17 00:00:00 2001 From: Bill-Gray Date: Thu, 18 Jul 2024 07:14:09 -0400 Subject: [PATCH 2/2] Due to preceding commit, windows can be created or moved beyond the right and bottom edges of the screen. (They could already be resized to do so, but you'd segfault when updating the window.) --- pdcurses/window.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pdcurses/window.c b/pdcurses/window.c index 9f425561..329fd5c7 100644 --- a/pdcurses/window.c +++ b/pdcurses/window.c @@ -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); @@ -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;