chan_dahdi: fix lower bound check with -ve integer conversion from a float
authorAlec L Davis <sivad.a@paradise.net.nz>
Thu, 2 May 2013 06:57:04 +0000 (06:57 +0000)
committerAlec L Davis <sivad.a@paradise.net.nz>
Thu, 2 May 2013 06:57:04 +0000 (06:57 +0000)
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

channels/chan_dahdi.c

index 7a8847e..fef6868 100644 (file)
@@ -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;