summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-06-09 14:38:20 -0400
committerJune McEnroe <june@causal.agency>2021-06-09 17:56:43 -0400
commit39efb5a3e215903e934d8d1c1b92c78f8b90e7ab (patch)
tree380c9d06af912ecbc5c994b42350fa1ae458cb97
parentUse seprintf for capList (diff)
downloadpounce-39efb5a3e215903e934d8d1c1b92c78f8b90e7ab.tar.gz
pounce-39efb5a3e215903e934d8d1c1b92c78f8b90e7ab.zip
Use seprintf for reserialize
Diffstat (limited to '')
-rw-r--r--client.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/client.c b/client.c
index a4ecb25..a1750bc 100644
--- a/client.c
+++ b/client.c
@@ -284,25 +284,20 @@ static const char *synthLabel(struct Client *client) {
 static void reserialize(
 	char *buf, size_t cap, const char *origin, const struct Message *msg
 ) {
-	size_t len = 0;
+	char *ptr = buf, *end = &buf[cap];
 	if (msg->tags) {
-		len += snprintf(&buf[len], cap - len, "@%s ", msg->tags);
-		if (len >= cap) return;
+		ptr = seprintf(ptr, end, "@%s ", msg->tags);
 	}
-	if (!origin) origin = msg->origin;
-	if (origin) {
-		len += snprintf(&buf[len], cap - len, ":%s ", origin);
-		if (len >= cap) return;
+	if (origin || msg->origin) {
+		ptr = seprintf(ptr, end, ":%s ", (origin ? origin : msg->origin));
 	}
-	len += snprintf(&buf[len], cap - len, "%s", msg->cmd);
-	if (len >= cap) return;
+	ptr = seprintf(ptr, end, "%s", msg->cmd);
 	for (size_t i = 0; i < ParamCap && msg->params[i]; ++i) {
 		if (i + 1 == ParamCap || !msg->params[i + 1]) {
-			len += snprintf(&buf[len], cap - len, " :%s", msg->params[i]);
+			ptr = seprintf(ptr, end, " :%s", msg->params[i]);
 		} else {
-			len += snprintf(&buf[len], cap - len, " %s", msg->params[i]);
+			ptr = seprintf(ptr, end, " %s", msg->params[i]);
 		}
-		if (len >= cap) return;
 	}
 }