summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-05-19 16:41:26 -0400
committerJune McEnroe <june@causal.agency>2021-05-19 16:42:39 -0400
commitf9e45b9d34a7ed8d2947b6ba3e0ba8f4dd8a5e0b (patch)
tree6c9b6b33ee555cbfdd1fe704f9542241f58bff91
parentReplace freenode with tilde.chat (diff)
downloadlitterbox-f9e45b9d34a7ed8d2947b6ba3e0ba8f4dd8a5e0b.tar.gz
litterbox-f9e45b9d34a7ed8d2947b6ba3e0ba8f4dd8a5e0b.zip
Fix MOTD buffer reallocation 1.8
Woops. Not how that should be done.
-rw-r--r--litterbox.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/litterbox.c b/litterbox.c
index a7c0e30..48e5b60 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -217,8 +217,10 @@ static void handleReplyMOTD(struct Message *msg) {
 	char *line = msg->params[1];
 	if (!strncmp(line, "- ", 2)) line += 2;
 	size_t len = strlen(line);
-	if (motd.len + len + 1 > motd.cap) {
-		motd.cap = (motd.cap ? motd.cap * 2 : len + 1);
+	size_t req = motd.len + len + 1;
+	if (req > motd.cap) {
+		if (!motd.cap) motd.cap = 1024;
+		while (req > motd.cap) motd.cap *= 2;
 		motd.buf = realloc(motd.buf, motd.cap);
 		if (!motd.buf) err(EX_OSERR, "realloc");
 	}