about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-05-17 18:03:38 -0400
committerJune McEnroe <june@causal.agency>2021-05-17 18:03:38 -0400
commit175fed4628acb9c46b073401c349a18154194ed7 (patch)
treecd3e64a000d650bccf4a581ea2a81d3873916960
parentAdd scoop -r reverse flag (diff)
downloadlitterbox-175fed4628acb9c46b073401c349a18154194ed7.tar.gz
litterbox-175fed4628acb9c46b073401c349a18154194ed7.zip
Avoid VLAs
People don't like them. I'm still not sold on their dangers or
whatever, but they're easy enough to avoid anyway.
-rw-r--r--scoop.c5
-rw-r--r--unscoop.c13
2 files changed, 12 insertions, 6 deletions
diff --git a/scoop.c b/scoop.c
index 156d5c8..6d06499 100644
--- a/scoop.c
+++ b/scoop.c
@@ -365,7 +365,9 @@ int main(int argc, char *argv[]) {
 	const char *limit = NULL;
 
 	int n = 0;
-	struct Bind binds[argc + 2];
+	struct Bind *binds = calloc(argc + 2, sizeof(*binds));
+	if (!binds) err(EX_OSERR, "calloc");
+
 	const char *Opts = "D:F:LN:ST:a:b:c:d:f:gh:l:m:n:pqrst:u:vw:";
 	for (int opt; 0 < (opt = getopt(argc, argv, Opts));) {
 		switch (opt) {
@@ -573,6 +575,7 @@ int main(int argc, char *argv[]) {
 			dbBindInt(stmt, binds[i].param, binds[i].value);
 		}
 	}
+	free(binds);
 
 	if (verbose) {
 		char *expand = sqlite3_expanded_sql(stmt);
diff --git a/unscoop.c b/unscoop.c
index 0ae16d9..72bf65f 100644
--- a/unscoop.c
+++ b/unscoop.c
@@ -352,7 +352,8 @@ int main(int argc, char *argv[]) {
 	}
 
 	regex_t pathRegex = compile(format->pattern);
-	regex_t regex[format->len];
+	regex_t *regex = calloc(format->len, sizeof(*regex));
+	if (!regex) err(EX_OSERR, "calloc");
 	for (size_t i = 0; i < format->len; ++i) {
 		regex[i] = compile(format->matchers[i].pattern);
 	}
@@ -388,10 +389,12 @@ int main(int argc, char *argv[]) {
 	size_t sizeTotal = 0;
 	size_t sizeRead = 0;
 	size_t sizePercent = -1;
-	regmatch_t match[argc][ParamCap];
+	struct {
+		regmatch_t match[ParamCap];
+	} *paths = calloc(argc, sizeof(*paths));
 
 	for (int i = optind; i < argc; ++i) {
-		int error = regexec(&pathRegex, argv[i], ParamCap, match[i], 0);
+		int error = regexec(&pathRegex, argv[i], ParamCap, paths[i].match, 0);
 		if (error && (!network || !context)) {
 			warnx("skipping %s", argv[i]);
 			argv[i] = NULL;
@@ -413,8 +416,8 @@ int main(int argc, char *argv[]) {
 		if (!file) err(EX_NOINPUT, "%s", argv[i]);
 		dbExec(SQL(BEGIN TRANSACTION;));
 
-		regmatch_t pathNetwork = match[i][format->network];
-		regmatch_t pathContext = match[i][format->context];
+		regmatch_t pathNetwork = paths[i].match[format->network];
+		regmatch_t pathContext = paths[i].match[format->context];
 		if (!network) {
 			bindMatch(insertContext, ":network", argv[i], pathNetwork);
 			bindMatch(insertEvent, ":network", argv[i], pathNetwork);