From 9e525c5bde1c740d6fbe377974a4abce80ace6cc Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 29 Jan 2022 03:52:27 +0000 Subject: [PATCH] array_grow(): fix wrong sizeof() The array_grow() function calculates the size by multiplying with sizeof(union Value*), where sizeof(union Value) was clearly meant. In practice, these are the same size on most (or maybe even all) systems, as no current member of union Value is larger than a pointer -- see name.h. But it's still wrong. --- src/cmd/ksh93/sh/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/ksh93/sh/array.c b/src/cmd/ksh93/sh/array.c index 0894d2cca..3a01b8051 100644 --- a/src/cmd/ksh93/sh/array.c +++ b/src/cmd/ksh93/sh/array.c @@ -819,7 +819,7 @@ static struct index_array *array_grow(Namval_t *np, register struct index_array errormsg(SH_DICT,ERROR_exit(1),e_subscript, fmtbase((long)maxi,10,0)); UNREACHABLE(); } - i = (newsize-1)*sizeof(union Value*)+newsize; + i = (newsize-1)*sizeof(union Value)+newsize; ap = new_of(struct index_array,i); memset((void*)ap,0,sizeof(*ap)+i); ap->maxi = newsize;