summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2017-11-07 11:41:08 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2017-11-07 11:41:08 +0000
commit9f135b3474640c9e0382b4d6b63404c6a1a47802 (patch)
tree14d7361ce55ce9ef003bdb15683605743cc62269 /usr.bin
parent9d46c0fb15ecc07a325c953463b8c3d836a13dfe (diff)
prefill with silence the buffer where cmap_copy() stores samples
rather than the client buffer. Fixes uninitialized data being treated as recorded samples when resampling or format conversions are involved but no mono->stereo conversion is used.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sndiod/dev.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/usr.bin/sndiod/dev.c b/usr.bin/sndiod/dev.c
index 642ea6386e6..801e36231be 100644
--- a/usr.bin/sndiod/dev.c
+++ b/usr.bin/sndiod/dev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dev.c,v 1.29 2017/11/03 17:12:59 ratchov Exp $ */
+/* $OpenBSD: dev.c,v 1.30 2017/11/07 11:41:07 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -1709,7 +1709,20 @@ slot_attach(struct slot *s)
enc_init(&s->sub.enc, &s->par, slot_nch);
s->sub.encbuf =
xmalloc(s->round * slot_nch * sizeof(adata_t));
- enc_sil_do(&s->sub.enc, s->sub.buf.data, s->appbufsz);
+ }
+
+ /*
+ * cmap_copy() doesn't write samples in all channels,
+ * for instance when mono->stereo conversion is
+ * disabled. So we have to prefill cmap_copy() output
+ * with silence.
+ */
+ if (s->sub.resampbuf) {
+ memset(s->sub.resampbuf, 0,
+ d->round * slot_nch * sizeof(adata_t));
+ } else if (s->sub.encbuf) {
+ memset(s->sub.encbuf, 0,
+ s->round * slot_nch * sizeof(adata_t));
} else {
memset(s->sub.buf.data, 0,
s->appbufsz * slot_nch * sizeof(adata_t));