restripe_lastframe: properly index into tmp/lastframe

pull/2166/head
nick black 3 years ago
parent bfdd5dd01d
commit 5a64f25ac2
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -4,6 +4,10 @@
#include <notcurses/direct.h> #include <notcurses/direct.h>
#include "internal.h" #include "internal.h"
// update for a new visual area of |rows|x|cols|, neither of which may be zero.
// copies that area of the lastframe (damage map) which is shared between the
// two. new areas are initialized to empty, just like a new plane. lost areas
// have their egcpool entries purged.
static nccell* static nccell*
restripe_lastframe(notcurses* nc, int rows, int cols){ restripe_lastframe(notcurses* nc, int rows, int cols){
assert(rows); assert(rows);
@ -13,7 +17,8 @@ restripe_lastframe(notcurses* nc, int rows, int cols){
if(tmp == NULL){ if(tmp == NULL){
return NULL; return NULL;
} }
size_t maxlinecopy = sizeof(nccell) * (nc->lfdimx > cols ? cols : nc->lfdimx); size_t copycols = nc->lfdimx > cols ? cols : nc->lfdimx;
size_t maxlinecopy = sizeof(nccell) * copycols;
size_t minlineset = sizeof(nccell) * cols - maxlinecopy; size_t minlineset = sizeof(nccell) * cols - maxlinecopy;
unsigned zorch = nc->lfdimx > cols ? nc->lfdimx - cols : 0; unsigned zorch = nc->lfdimx > cols ? nc->lfdimx - cols : 0;
for(int y = 0 ; y < rows ; ++y){ for(int y = 0 ; y < rows ; ++y){
@ -22,11 +27,11 @@ restripe_lastframe(notcurses* nc, int rows, int cols){
memcpy(&tmp[cols * y], &nc->lastframe[nc->lfdimx * y], maxlinecopy); memcpy(&tmp[cols * y], &nc->lastframe[nc->lfdimx * y], maxlinecopy);
} }
if(minlineset){ if(minlineset){
memset(&tmp[cols * y + maxlinecopy / sizeof(nccell)], 0, minlineset); memset(&tmp[cols * y + copycols], 0, minlineset);
} }
// excise any egcpool entries from the right of the new plane area // excise any egcpool entries from the right of the new plane area
if(zorch){ if(zorch){
for(unsigned x = maxlinecopy ; x < maxlinecopy + zorch ; ++x){ for(unsigned x = copycols ; x < copycols + zorch ; ++x){
pool_release(&nc->pool, &nc->lastframe[fbcellidx(y, nc->lfdimx, x)]); pool_release(&nc->pool, &nc->lastframe[fbcellidx(y, nc->lfdimx, x)]);
} }
} }

Loading…
Cancel
Save