about summary refs log tree commit diff
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
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) {
span='3' class='logmsg'> 2021-09-15Set bot mode on downgradeJune McEnroe 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe Also bump the message cap to 1024 because that is ostensibly useful for replying to older messages. 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe There are probably better things to sort by but title definitely always exists. 2021-09-13Swap-remove tags as they're foundJune McEnroe This makes it even faster. From ~1s on a sqlite3.c amalgamation to ~0.85s. 2021-09-12Replace htagml regex with strncmpJune McEnroe Since ctags only ever produces regular expressions of the form /^re$/ or /^re/ with no other special characters, instead unescape the pattern and simply use strncmp. Running on a sqlite3.c amalgamation, the regex version takes ~37s while the strncmp version takes ~1s, producing identical output. Big win! 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe This fixes badly indented comments. 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe