mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
avcodec/adxenc: Avoid undefined left shift of negative numbers
Replace "((a << shift) + b) >> shift" by "a + (b >> shift)". This avoids a left shift which also happens to trigger undefined behaviour in case "a" is negative. This affected the FATE-tests acodec-adpcm-adx and acodec-adpcm-adx-trellis; it also fixes ticket #8008. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 59a9d65e0d790821f88527a82569f56eb2f8a9be) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
8c9132a88e
commit
c103c203dd
@ -48,7 +48,7 @@ static void adx_encode(ADXContext *c, uint8_t *adx, const int16_t *wav,
|
|||||||
s2 = prev->s2;
|
s2 = prev->s2;
|
||||||
for (i = 0, j = 0; j < 32; i += channels, j++) {
|
for (i = 0, j = 0; j < 32; i += channels, j++) {
|
||||||
s0 = wav[i];
|
s0 = wav[i];
|
||||||
d = ((s0 << COEFF_BITS) - c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS;
|
d = s0 + ((-c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS);
|
||||||
if (max < d)
|
if (max < d)
|
||||||
max = d;
|
max = d;
|
||||||
if (min > d)
|
if (min > d)
|
||||||
@ -79,13 +79,13 @@ static void adx_encode(ADXContext *c, uint8_t *adx, const int16_t *wav,
|
|||||||
s1 = prev->s1;
|
s1 = prev->s1;
|
||||||
s2 = prev->s2;
|
s2 = prev->s2;
|
||||||
for (i = 0, j = 0; j < 32; i += channels, j++) {
|
for (i = 0, j = 0; j < 32; i += channels, j++) {
|
||||||
d = ((wav[i] << COEFF_BITS) - c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS;
|
d = wav[i] + ((-c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS);
|
||||||
|
|
||||||
d = av_clip_intp2(ROUNDED_DIV(d, scale), 3);
|
d = av_clip_intp2(ROUNDED_DIV(d, scale), 3);
|
||||||
|
|
||||||
put_sbits(&pb, 4, d);
|
put_sbits(&pb, 4, d);
|
||||||
|
|
||||||
s0 = ((d << COEFF_BITS) * scale + c->coeff[0] * s1 + c->coeff[1] * s2) >> COEFF_BITS;
|
s0 = d * scale + ((c->coeff[0] * s1 + c->coeff[1] * s2) >> COEFF_BITS);
|
||||||
s2 = s1;
|
s2 = s1;
|
||||||
s1 = s0;
|
s1 = s0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user