[FFmpeg-cvslog] avcodec/mpegaudioenc_template: reorder operations to prevent integer overflow
Michael Niedermayer
git at videolan.org
Wed Apr 9 07:37:20 CEST 2014
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Apr 9 06:56:53 2014 +0200| [44841528c197435be44f0c3598098e6c52f0df26] | committer: Michael Niedermayer
avcodec/mpegaudioenc_template: reorder operations to prevent integer overflow
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=44841528c197435be44f0c3598098e6c52f0df26
---
libavcodec/mpegaudioenc_template.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libavcodec/mpegaudioenc_template.c b/libavcodec/mpegaudioenc_template.c
index 5ae4269..451d140 100644
--- a/libavcodec/mpegaudioenc_template.c
+++ b/libavcodec/mpegaudioenc_template.c
@@ -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)
More information about the ffmpeg-cvslog
mailing list