diff options
author | Kevin P. Fleming <kpfleming@digium.com> | 2005-10-28 21:35:55 +0000 |
---|---|---|
committer | Kevin P. Fleming <kpfleming@digium.com> | 2005-10-28 21:35:55 +0000 |
commit | 8dad624c68b5f920f810f76e3b49741f991b6ae6 (patch) | |
tree | 516b6bc501ba5df920323c0dfd62cd355698de65 /include | |
parent | c24ba6ac5edf876e9c018faf2c604eb1e3b97d45 (diff) |
ensure that SLINEAR volume adjustments don't wrap around short integer maximums
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6882 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rwxr-xr-x | include/asterisk/utils.h | 30 |
1 files changed, 30 insertions, 0 deletions
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); |