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.
This commit is contained in:
Michael Forney 2019-04-16 17:44:08 -07:00
parent 3fec3e2f4c
commit ef9f6f359a
1 changed files with 4 additions and 2 deletions

6
expr.c
View File

@ -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: