summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
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;
 	}
 }