[Asterisk-Dev] Re: asterisk/include/asterisk utils.h,1.46,1.47
Tony Mountifield
tony at softins.clara.co.uk
Sat Oct 29 02:30:20 MST 2005
Comments below...
In article <20051028224320.E30312FC47A at lists.digium.com>,
<kpfleming at lists.digium.com> wrote:
> Update of /usr/cvsroot/asterisk/include/asterisk
> In directory mongoose.digium.com:/tmp/cvs-serv2563/include/asterisk
>
> Modified Files:
> utils.h
> Log Message:
> ensure that SLINEAR volume adjustments don't wrap around short integer maximums
>
>
> Index: utils.h
> ===================================================================
> RCS file: /usr/cvsroot/asterisk/include/asterisk/utils.h,v
> retrieving revision 1.46
> retrieving revision 1.47
> diff -u -d -r1.46 -r1.47
> --- utils.h 24 Oct 2005 20:12:06 -0000 1.46
> +++ utils.h 28 Oct 2005 21:35:55 -0000 1.47
> @@ -168,7 +168,37 @@
> \param s String to be decoded
> */
> void ast_uri_decode(char *s);
> +
> +static inline void ast_slinear_saturated_add(short *input, short value)
> +{
> + int res;
> +
> + res = *input + value;
This should be: res = (int)*input + value;
Without the cast, I believe the compiler is at liberty to evaluate the RHS
in short precision (which might still overflow) and only extend on assigning
the result to res.
> + if (res > 32767)
> + *input = 32767;
> + else if (res < -32767)
> + *input = -32767;
> + else
> + *input = (short) res;
> +}
>
> +static inline void ast_slinear_saturated_multiply(short *input, short value)
> +{
> + int res;
> +
> + res = *input * value;
res = (int)*input * value;
> + if (res > 32767)
> + *input = 32767;
> + else if (res < -32767)
> + *input = -32767;
> + else
> + *input = (short) res;
> +}
> +
> +static inline void ast_slinear_saturated_divide(short *input, short value)
> +{
> + *input /= value;
> +}
>
> extern int test_for_thread_safety(void);
Cheers
Tony
--
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org
More information about the asterisk-dev
mailing list