Hello Yasuoka-san,

YASUOKA Masahiko wrote on Mon, Aug 05, 2019 at 04:20:41PM +0900:

> This is the diff which fixes the problem by replacing malloc by calloc.
> 
> Initialize the line buffer by zero when allocation.  This fixes the
> problem a crash happens after the window size change.

Actually, only the two "b[i] = calloc(..." changes are needed.
The two "b = calloc(..." are pointless because b[] is already
explicitly and completely initialized four lines below.

Then again, even though i doubt that we still regard NetBSD as
"upstream" for libedit, we do still compare code occasionally, so
avoiding gratuitious differences still makes sense.

In this case, the "b = calloc(..." is harmless precisely because the
initializarion has absolutely no effect, being completely overwritten
four lines below.  Performance is irrelevant here because this function
is called quite rarely and certainly not in a loop.

So the diff is OK schwarze@ as is.

Thanks for tracking this down and finding the best fix.

Yours,
  Ingo


> Index: lib/libedit/terminal.c
> ===================================================================
> RCS file: /cvs/src/lib/libedit/terminal.c,v
> retrieving revision 1.18
> diff -u -p -r1.18 terminal.c
> --- lib/libedit/terminal.c    12 Apr 2017 18:24:37 -0000      1.18
> +++ lib/libedit/terminal.c    5 Aug 2019 07:13:08 -0000
> @@ -413,11 +413,11 @@ terminal_alloc_display(EditLine *el)
>       wchar_t **b;
>       coord_t *c = &el->el_terminal.t_size;
>  
> -     b = reallocarray(NULL, c->v + 1, sizeof(*b));
> +     b = calloc(c->v + 1, sizeof(*b));
>       if (b == NULL)
>               goto done;
>       for (i = 0; i < c->v; i++) {
> -             b[i] = reallocarray(NULL, c->h + 1, sizeof(**b));
> +             b[i] = calloc(c->h + 1, sizeof(**b));
>               if (b[i] == NULL) {
>                       while (--i >= 0)
>                               free(b[i]);
> @@ -428,11 +428,11 @@ terminal_alloc_display(EditLine *el)
>       b[c->v] = NULL;
>       el->el_display = b;
>  
> -     b = reallocarray(NULL, c->v + 1, sizeof(*b));
> +     b = calloc(c->v + 1, sizeof(*b));
>       if (b == NULL)
>               goto done;
>       for (i = 0; i < c->v; i++) {
> -             b[i] = reallocarray(NULL, c->h + 1, sizeof(**b));
> +             b[i] = calloc(c->h + 1, sizeof(**b));
>               if (b[i] == NULL) {
>                       while (--i >= 0)
>                               free(b[i]);

Reply via email to