aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2017-05-06 21:31:49 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2017-05-14 12:20:15 +0200
commit1bb1d2d4a1ca53afbe5f6b82c12e5238c73e4496 (patch)
tree3f9f4a84f4feffdf2b7d1043bad1cd000fac2d92
parentf20c485e4e4185a849e6d15b240459f4385966b3 (diff)
downloadffmpeg-1bb1d2d4a1ca53afbe5f6b82c12e5238c73e4496.tar.gz
avutil/softfloat: Fix overflow in av_div_sf()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 277e397eb5964999bd76909f52d4bd3350289c22) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavutil/softfloat.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/libavutil/softfloat.h b/libavutil/softfloat.h
index fed3e77f87..daf91a5557 100644
--- a/libavutil/softfloat.h
+++ b/libavutil/softfloat.h
@@ -114,8 +114,15 @@ static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
* @return Will not be more denormalized than a.
*/
static inline av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
+ int64_t temp = (int64_t)a.mant * (1<<(ONE_BITS+1));
+ temp /= b.mant;
a.exp -= b.exp;
- a.mant = ((int64_t)a.mant<<(ONE_BITS+1)) / b.mant;
+ a.mant = temp;
+ while (a.mant != temp) {
+ temp /= 2;
+ a.exp--;
+ a.mant = temp;
+ }
a = av_normalize1_sf(a);
if (!a.mant || a.exp < MIN_EXP)
return FLOAT_0;