modules: convert snprintf to strbuf

Use spa_strbuf instead of snprintf to handle errors better.
This commit is contained in:
Wim Taymans 2026-05-06 13:35:09 +02:00
parent 2c4dc2d22f
commit 51b635cc98
4 changed files with 25 additions and 16 deletions

View file

@ -632,13 +632,15 @@ static struct client_data *client_new(struct server *s, int fd)
pw_log_warn("server %p: security label error: %m", s);
} else {
if (!check_print(buffer, len)) {
char *hex, *p;
char *hex;
struct spa_strbuf b;
static const char *ch = "0123456789abcdef";
p = hex = alloca(len * 2 + 10);
p += snprintf(p, 5, "hex:");
hex = alloca(len * 2 + 10);
spa_strbuf_init(&b, hex, len * 2 + 10);
spa_strbuf_append(&b, "hex:");
for(i = 0; i < (int)len; i++)
p += snprintf(p, 3, "%c%c",
spa_strbuf_append(&b, "%c%c",
ch[buffer[i] >> 4], ch[buffer[i] & 0xf]);
pw_properties_set(props, PW_KEY_SEC_LABEL, hex);