avutil/softfloat: Fix overflow in av_div_sf()
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 6 May 2017 19:31:49 +0000 (21:31 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Wed, 17 May 2017 18:35:19 +0000 (20:35 +0200)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 277e397eb5964999bd76909f52d4bd3350289c22)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavutil/softfloat.h

index 8e28a0e..b4fce57 100644 (file)
@@ -110,8 +110,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;