summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-06-09 14:37:57 -0400
committerJune McEnroe <june@causal.agency>2021-06-09 17:56:43 -0400
commitd2d3901e13a7cd879611e1cf7f8a0de39eb125af (patch)
tree509c2e2028c4ea0e163801f180d263a1587d9005
parentAdd seprintf (diff)
downloadpounce-d2d3901e13a7cd879611e1cf7f8a0de39eb125af.tar.gz
pounce-d2d3901e13a7cd879611e1cf7f8a0de39eb125af.zip
Use seprintf for capList
-rw-r--r--bounce.h14
1 files changed, 6 insertions, 8 deletions
diff --git a/bounce.h b/bounce.h
index 2010d45..e17f216 100644
--- a/bounce.h
+++ b/bounce.h
@@ -152,17 +152,15 @@ static inline enum Cap capParse(const char *list, const char *values[CapBits]) {
 static inline const char *capList(enum Cap caps, const char *values[CapBits]) {
 	static char buf[1024];
 	buf[0] = '\0';
-	size_t len = 0;
+	char *ptr = buf, *end = &buf[sizeof(buf)];
 	for (size_t i = 0; i < ARRAY_LEN(CapNames); ++i) {
 		if (caps & (1 << i)) {
-			len += snprintf(
-				&buf[len], sizeof(buf) - len,
-				"%s%s%s%s",
-				(len ? " " : ""), CapNames[i],
-				(values && values[i] ? "=" : ""),
-				(values && values[i] ? values[i] : "")
+			ptr = seprintf(
+				ptr, end, "%s%s", (ptr > buf ? " " : ""), CapNames[i]
 			);
-			if (len >= sizeof(buf)) break;
+			if (values && values[i]) {
+				ptr = seprintf(ptr, end, "=%s", values[i]);
+			}
 		}
 	}
 	return buf;