]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Use the proper lower bound when doing saturation arithmetic.
authorSean Bright <sean@malleable.com>
Tue, 30 Apr 2013 13:45:40 +0000 (13:45 +0000)
committerSean Bright <sean@malleable.com>
Tue, 30 Apr 2013 13:45:40 +0000 (13:45 +0000)
16 bit signed integers have a range of [-32768, 32768).  The existing code
was using the interval (-32768, 32768) instead.  This patch fixes that.

Review: https://reviewboard.asterisk.org/r/2479/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@386929 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/utils.h

index aa927cc3612608de1f7d8979586cf59c293d8634..415e39673007ae6a110d460e554fa3fd67159c4a 100644 (file)
@@ -307,8 +307,8 @@ static force_inline void ast_slinear_saturated_add(short *input, short *value)
        res = (int) *input + *value;
        if (res > 32767)
                *input = 32767;
-       else if (res < -32767)
-               *input = -32767;
+       else if (res < -32768)
+               *input = -32768;
        else
                *input = (short) res;
 }
@@ -320,8 +320,8 @@ static force_inline void ast_slinear_saturated_subtract(short *input, short *val
        res = (int) *input - *value;
        if (res > 32767)
                *input = 32767;
-       else if (res < -32767)
-               *input = -32767;
+       else if (res < -32768)
+               *input = -32768;
        else
                *input = (short) res;
 }
@@ -333,8 +333,8 @@ static force_inline void ast_slinear_saturated_multiply(short *input, short *val
        res = (int) *input * *value;
        if (res > 32767)
                *input = 32767;
-       else if (res < -32767)
-               *input = -32767;
+       else if (res < -32768)
+               *input = -32768;
        else
                *input = (short) res;
 }