comparison ra144.c @ 6855:128af7cac045 libavcodec

Use an intermediate variable for overflow testing
author vitor
date Sat, 24 May 2008 16:38:48 +0000
parents d4c8338a09a8
children e62bb30dc9ea
comparison
equal deleted inserted replaced
6854:d4c8338a09a8 6855:128af7cac045
152 memcpy(work, statbuf,20); 152 memcpy(work, statbuf,20);
153 memcpy(work + 10, i2, len * 2); 153 memcpy(work + 10, i2, len * 2);
154 154
155 for (i=0; i<len; i++) { 155 for (i=0; i<len; i++) {
156 int sum = 0; 156 int sum = 0;
157 int new_val;
157 158
158 for(x=0; x<10; x++) 159 for(x=0; x<10; x++)
159 sum += i1[9-x] * ptr[x]; 160 sum += i1[9-x] * ptr[x];
160 161
161 sum >>= 12; 162 sum >>= 12;
162 163
163 if (ptr[10] - sum < -32768 || ptr[10] - sum > 32767) { 164 new_val = ptr[10] - sum;
165
166 if (new_val < -32768 || new_val > 32767) {
164 memset(out, 0, len * 2); 167 memset(out, 0, len * 2);
165 memset(statbuf, 0, 20); 168 memset(statbuf, 0, 20);
166 return; 169 return;
167 } 170 }
168 171
169 ptr[10] -= sum; 172 ptr[10] = new_val;
170 ptr++; 173 ptr++;
171 } 174 }
172 175
173 memcpy(out, work+10, len * 2); 176 memcpy(out, work+10, len * 2);
174 memcpy(statbuf, work + 40, 20); 177 memcpy(statbuf, work + 40, 20);