From 320fe9a6a0dcf64f9de40da6ea555b7a2484a970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 6 May 2026 21:45:44 +0200 Subject: [PATCH] spa: alsa: pcm: log_write(): don't use `strcspn()` Do not use `strcspn()` because it assumes a null terminated string, but the `fopencookie()` write callback receives a (ptr, length) pair. So use `memchr()` instead to find the `\n`. --- spa/plugins/alsa/alsa-pcm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index f99787828..61a1a4b26 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -714,16 +714,18 @@ int spa_alsa_parse_prop_params(struct state *state, struct spa_pod *params) static ssize_t log_write(void *cookie, const char *buf, size_t size) { struct state *state = cookie; - int len; for (size_t left = size; left > 0; ) { - len = strcspn(buf, "\n"); + const char *end = memchr(buf, '\n', left); + size_t len = end ? end - buf : left; if (len > 0) spa_log_debug(state->log, "%.*s", (int)len, buf); - buf += len + 1; - left -= len + 1; + + buf += len + !!end; + left -= len + !!end; } + return size; }