sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit ef9f6f359a0762b738302ae05822514d72b70450
parent 3fec3e2f4cd0d4b5dfe2f851dc135787f0e377fe
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 16 Apr 2019 17:44:08 -0700

expr: Allocate arrays with reallocarray instead of VLA

The length of these arrays is user input, and this is the only use of
VLAs in sbase.

Diffstat:
Mexpr.c | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/expr.c b/expr.c @@ -194,8 +194,8 @@ lex(char *s, struct val *v) static int parse(char *expr[], int numexpr) { - struct val valhead[numexpr], *valp = valhead, v = { .str = NULL, .num = 0 }; - int ophead[numexpr], *opp = ophead, type, lasttype = 0; + struct val *valhead, *valp, v = { .str = NULL, .num = 0 }; + int *ophead, *opp, type, lasttype = 0; char prec[] = { [ 0 ] = 0, [VAL] = 0, ['('] = 0, [')'] = 0, ['|'] = 1, @@ -206,6 +206,8 @@ parse(char *expr[], int numexpr) [':'] = 6, }; + valp = valhead = enreallocarray(3, NULL, numexpr, sizeof(*valp)); + opp = ophead = enreallocarray(3, NULL, numexpr, sizeof(*opp)); for (; *expr; expr++) { switch ((type = lex(*expr, &v))) { case VAL: