From bba43d4433994119a2196a48718f5e1115601590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Wed, 6 May 2026 21:58:11 +0200 Subject: [PATCH] spa: alsa: pcm: log_write(): fix return value The `fopencookie()` write callback should return the number of consumed bytes, but it currently only ever returns 0, which signals an error condition according to the documentation. Fix that by not overwriting `size`. Fixes: 73073eb33fda ("alsa: redirect alsa output to log file") --- spa/plugins/alsa/alsa-pcm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 0df9f5aa7..cd0a53c22 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -718,12 +718,13 @@ static ssize_t log_write(void *cookie, const char *buf, size_t size) struct state *state = cookie; int len; - while (size > 0) { + for (size_t left = size; left > 0; ) { len = strcspn(buf, "\n"); + if (len > 0) spa_log_debug(state->log, "%.*s", (int)len, buf); buf += len + 1; - size -= len + 1; + left -= len + 1; } return size; }