about summary refs log tree commit diff
diff options
context:
space:
mode:
-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");
 	}