From d2d3901e13a7cd879611e1cf7f8a0de39eb125af Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 9 Jun 2021 14:37:57 -0400 Subject: Use seprintf for capList --- bounce.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'bounce.h') 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; -- cgit 1.4.1