Skip to content

Commit

Permalink
Scrolling was broken ever since we switched from line-by-line allocat…
Browse files Browse the repository at this point in the history
…ion for windows to allocating all lines at once. The existing code rearraged line pointers, so that win->_y[0] was no longer the pointer that ought to be freed. Solution was to scroll without rearranging line pointers.
  • Loading branch information
Bill-Gray committed Jan 7, 2023
1 parent 9d1a733 commit 72521a1
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions pdcurses/scroll.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <curspriv.h>
#include <assert.h>
#include <string.h>

/*man-start**************************************************************
Expand Down Expand Up @@ -41,8 +42,8 @@ scroll

int wscrl(WINDOW *win, int n)
{
int i, l, dir, start, end;
chtype blank, *temp;
int start, end, n_lines;
chtype blank, *tptr, *endptr;

/* Check if window scrolls. Valid for window AND pad */

Expand All @@ -51,38 +52,35 @@ int wscrl(WINDOW *win, int n)
return ERR;

blank = win->_bkgd;
start = win->_tmarg;
end = win->_bmarg + 1;
n_lines = end - start;

if (n > 0)
if (n > 0) /* scroll up */
{
start = win->_tmarg;
end = win->_bmarg;
dir = 1;
if( n > n_lines)
n = n_lines;
memmove( win->_y[start], win->_y[start + n],
(n_lines - n) * win->_maxx * sizeof( chtype));
tptr = win->_y[end - n];
}
else
else /* scroll down */
{
start = win->_bmarg;
end = win->_tmarg;
dir = -1;
n = -n;
if( n > n_lines)
n = n_lines;
memmove( win->_y[start + n], win->_y[start],
(n_lines - n) * win->_maxx * sizeof( chtype));
tptr = win->_y[win->_tmarg];
}

for (l = 0; l < (n * dir); l++)
{
temp = win->_y[start];

/* re-arrange line pointers */

for (i = start; i != end; i += dir)
win->_y[i] = win->_y[i + dir];
/* make blank lines */

win->_y[end] = temp;

/* make a blank line */

for (i = 0; i < win->_maxx; i++)
*temp++ = blank;
}
endptr = tptr + n * win->_maxx;
while( tptr < endptr)
*tptr++ = blank;

touchline(win, win->_tmarg, win->_bmarg - win->_tmarg + 1);
touchline(win, start, n_lines);

PDC_sync(win);
return OK;
Expand Down

0 comments on commit 72521a1

Please sign in to comment.