Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev When this code was split from dev/pad, the "volume" ...



details:   https://anonhg.NetBSD.org/src/rev/f5014e2858cc
branches:  trunk
changeset: 333950:f5014e2858cc
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Nov 23 12:23:25 2014 +0000

description:
When this code was split from dev/pad, the "volume" member size was changed
from u_int to uint8_t. This had the unfortunate side-effect of introducing
an integer overflow when adjusting samples as the largest type used was now
int16_t. This change copies the volume level to a temporary u_int and uses
that in the calculation. Should fix recent failures with the
dev/audio/t_pad/pad_output test.

diffstat:

 sys/dev/auvolconv.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (62 lines):

diff -r b4c5b84cf646 -r f5014e2858cc sys/dev/auvolconv.c
--- a/sys/dev/auvolconv.c       Sun Nov 23 11:08:16 2014 +0000
+++ b/sys/dev/auvolconv.c       Sun Nov 23 12:23:25 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: auvolconv.c,v 1.1 2014/11/18 01:53:17 jmcneill Exp $ */
+/* $NetBSD: auvolconv.c,v 1.2 2014/11/23 12:23:25 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: auvolconv.c,v 1.1 2014/11/18 01:53:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auvolconv.c,v 1.2 2014/11/23 12:23:25 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -49,10 +49,12 @@
        stream_filter_t *this;
        int16_t j, *wp;
        int m, err;
+       u_int vol;
 
        pf = (auvolconv_filter_t *)self;
        this = &pf->base;
        max_used = (max_used + 1) & ~1;
+       vol = *pf->vol;
 
        if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used)))
                return err;
@@ -61,7 +63,7 @@
        FILTER_LOOP_PROLOGUE(this->src, 2, dst, 2, m) {
                j = le16dec(s);
                wp = (int16_t *)d;
-               le16enc(wp, (j * *pf->vol) / 255);
+               le16enc(wp, (j * vol) / 255);
        } FILTER_LOOP_EPILOGUE(this->src, dst);
 
        return 0;
@@ -75,10 +77,12 @@
        stream_filter_t *this;
        int16_t j, *wp;
        int m, err;
+       u_int vol;
 
        pf = (auvolconv_filter_t *)self;
        this = &pf->base;
        max_used = (max_used + 1) & ~1;
+       vol = *pf->vol;
 
        if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used)))
                return err;
@@ -87,7 +91,7 @@
        FILTER_LOOP_PROLOGUE(this->src, 2, dst, 2, m) {
                j = be16dec(s);
                wp = (int16_t *)d;
-               be16enc(wp, (j * *pf->vol) / 255);
+               be16enc(wp, (j * vol) / 255);
        } FILTER_LOOP_EPILOGUE(this->src, dst);
 
        return 0;



Home | Main Index | Thread Index | Old Index