From: Alec L Davis Date: Thu, 2 May 2013 06:57:04 +0000 (+0000) Subject: chan_dahdi: fix lower bound check with -ve integer conversion from a float X-Git-Tag: 13.0.0-beta1~1858 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b020e8c0bcac71309ddb050f5d033053b1d2419;p=thirdparty%2Fasterisk.git chan_dahdi: fix lower bound check with -ve integer conversion from a float Lower bound of a 16bit signed int is -32768 not -32767 (closes issue ASTERISK-21744) Reported by: alecdavis Tested by: alecdavis alecdavis (license 585) ........ Merged revisions 387297 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 387298 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387299 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index 7a8847e8b6..fef6868959 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -5150,9 +5150,12 @@ static void fill_txgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->txgain[j] = AST_LIN2A(k); } else { g->txgain[j] = j; @@ -5166,9 +5169,12 @@ static void fill_txgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->txgain[j] = AST_LIN2MU(k); } else { @@ -5193,9 +5199,12 @@ static void fill_rxgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->rxgain[j] = AST_LIN2A(k); } else { g->rxgain[j] = j; @@ -5209,9 +5218,12 @@ static void fill_rxgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->rxgain[j] = AST_LIN2MU(k); } else { g->rxgain[j] = j;