summary refs log tree commit diff
path: root/scoop.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-24 14:19:41 -0400
committerJune McEnroe <june@causal.agency>2020-07-24 14:19:41 -0400
commit434a537d660d41b030e409a3c3d9d0ffafe0c8f2 (patch)
tree482b43bb94f0ab2b0e31271bdde9337d64afa6bb /scoop.c
parentFix select #define (diff)
downloadlitterbox-434a537d660d41b030e409a3c3d9d0ffafe0c8f2.tar.gz
litterbox-434a537d660d41b030e409a3c3d9d0ffafe0c8f2.zip
Use asprintf to concatenate query
Newer gcc will point out that concatenating 3 buffers of 4096 bytes into
a buffer of 4096 might truncate, which I don't care about because the
query should never be 4K anyway, but it's simple to use asprintf here.
Diffstat (limited to '')
-rw-r--r--scoop.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/scoop.c b/scoop.c
index 4721c73..c71e99d 100644
--- a/scoop.c
+++ b/scoop.c
@@ -536,10 +536,10 @@ int main(int argc, char *argv[]) {
 	}
 
 	sqlite3_stmt *stmt;
-	char query[QueryCap];
+	char *query = NULL;
 	if (sort) {
-		snprintf(
-			query, sizeof(query),
+		asprintf(
+			&query,
 			SQL(
 				WITH results AS (%s %s %s)
 				SELECT * FROM results
@@ -548,9 +548,11 @@ int main(int argc, char *argv[]) {
 			select, from, where, (group ? "network, context," : "")
 		);
 	} else {
-		snprintf(query, sizeof(query), "%s %s %s;", select, from, where);
+		asprintf(&query, "%s %s %s;", select, from, where);
 	}
+	if (!query) err(EX_OSERR, "asprintf");
 	stmt = dbPrepare(query);
+	free(query);
 
 	for (int i = 0; i < n; ++i) {
 		if (binds[i].text) {