From 434a537d660d41b030e409a3c3d9d0ffafe0c8f2 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 24 Jul 2020 14:19:41 -0400 Subject: 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. --- scoop.c | 10 ++++++---- 1 file 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) { -- cgit 1.4.1