[hackers] [sbase] expr: Allocate arrays with reallocarray instead of VLA || Michael Forney
commit ef9f6f359a0762b738302ae05822514d72b70450
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Tue Apr 16 17:44:08 2019 -0700
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Tue Apr 16 17:44:08 2019 -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.
diff --git a/expr.c b/expr.c
index d9c758d..1299200 100644
--- a/expr.c
+++ b/expr.c
_AT_@ -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,
_AT_@ -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:
Received on Wed Apr 17 2019 - 03:03:28 CEST
This archive was generated by hypermail 2.3.0
: Wed Apr 17 2019 - 03:12:22 CEST