avcodec/mpegaudioenc_template: reorder operations to prevent integer overflow

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-04-09 06:56:53 +02:00
parent 9d66aa2c8f
commit 44841528c1

View File

@ -700,9 +700,10 @@ static void encode_frame(MpegAudioContext *s,
else
q1 = sample >> shift;
q1 = (q1 * mult) >> P;
q[m] = ((q1 + (1 << P)) * steps) >> (P + 1);
if (q[m] < 0)
q[m] = 0;
q1 += 1 << P;
if (q1 < 0)
q1 = 0;
q[m] = (unsigned)(q1 * steps) >> (P + 1);
}
#endif
if (q[m] >= steps)