[ncplane_new] allocate based on true length #1472

This commit is contained in:
nick black 2021-03-27 06:43:29 -04:00 committed by Nick Black
parent 1688f66bc7
commit 7c5b7fe85c

View File

@ -320,14 +320,6 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n,
if(p == NULL){ if(p == NULL){
return NULL; return NULL;
} }
size_t fbsize = sizeof(*p->fb) * (nopts->rows * nopts->cols);
if((p->fb = malloc(fbsize)) == NULL){
logerror(nc, "Error allocating cellmatrix (r=%d, c=%d)\n",
nopts->rows, nopts->cols);
free(p);
return NULL;
}
memset(p->fb, 0, fbsize);
p->scrolling = false; p->scrolling = false;
if(nopts->flags & NCPLANE_OPTION_MARGINALIZED){ if(nopts->flags & NCPLANE_OPTION_MARGINALIZED){
p->margin_b = nopts->margin_b; p->margin_b = nopts->margin_b;
@ -348,6 +340,14 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n,
p->leny = nopts->rows; p->leny = nopts->rows;
p->lenx = nopts->cols; p->lenx = nopts->cols;
} }
size_t fbsize = sizeof(*p->fb) * (p->leny * p->lenx);
if((p->fb = malloc(fbsize)) == NULL){
logerror(nc, "Error allocating cellmatrix (r=%d, c=%d)\n",
p->leny, p->lenx);
free(p);
return NULL;
}
memset(p->fb, 0, fbsize);
p->x = p->y = 0; p->x = p->y = 0;
p->logrow = 0; p->logrow = 0;
p->sprite = NULL; p->sprite = NULL;