From cfe9c7d6caa550c23bd64813b2776d73ab734e9b 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 cd0a53c22..1b6d74824 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -716,16 +716,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; }