From 7c5b7fe85c2e7498634fa91bf244751912990f87 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 27 Mar 2021 06:43:29 -0400 Subject: [PATCH] [ncplane_new] allocate based on true length #1472 --- src/lib/notcurses.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index b69351fe3..4244cfe97 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -320,14 +320,6 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n, if(p == 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; if(nopts->flags & NCPLANE_OPTION_MARGINALIZED){ p->margin_b = nopts->margin_b; @@ -348,6 +340,14 @@ ncplane* ncplane_new_internal(notcurses* nc, ncplane* n, p->leny = nopts->rows; 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->logrow = 0; p->sprite = NULL;