avcodec/mpegaudioenc_template: reorder operations to prevent integer overflow
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 9 Apr 2014 04:56:53 +0000 (06:56 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 9 Apr 2014 05:04:12 +0000 (07:04 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/mpegaudioenc_template.c

index 5ae4269..451d140 100644 (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)