From dc1aa1ffdc495cfff0c483ac6056bc8b203ee3ff Mon Sep 17 00:00:00 2001 From: kpfleming Date: Fri, 28 Oct 2005 21:35:55 +0000 Subject: ensure that SLINEAR volume adjustments don't wrap around short integer maximums git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6882 f38db490-d61c-443f-a65b-d21fe96a405b --- include/asterisk/utils.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include/asterisk/utils.h') diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index e0c32597d..9aa1a34c3 100755 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -168,7 +168,37 @@ char *ast_uri_encode(char *string, char *outbuf, int buflen, int doreserved); \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; + 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; + 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); -- cgit v1.2.3