]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/half2float: fix integer overflows in convertmantissa()
authorPaul B Mahol <onemda@gmail.com>
Wed, 3 Mar 2021 11:37:02 +0000 (12:37 +0100)
committerPaul B Mahol <onemda@gmail.com>
Wed, 3 Mar 2021 11:41:44 +0000 (12:41 +0100)
libavcodec/half2float.h

index 9cff12a3096cd74fbd049409e042d429ebee0dd9..fd11caffdf762b9fe021c857a7f13d8acbfb253e 100644 (file)
 
 static uint32_t convertmantissa(uint32_t i)
 {
-    uint32_t m = i << 13; // Zero pad mantissa bits
-    uint32_t e = 0; // Zero exponent
+    int32_t m = i << 13; // Zero pad mantissa bits
+    int32_t e = 0; // Zero exponent
 
-    while (!(m & 0x00800000UL)){ // While not normalized
-        e -= 0x00800000UL; // Decrement exponent (1<<23)
+    while (!(m & 0x00800000)) { // While not normalized
+        e -= 0x00800000; // Decrement exponent (1<<23)
         m <<= 1; // Shift mantissa
     }
 
-    m &= ~0x00800000UL; // Clear leading 1 bit
-    e +=  0x38800000UL; // Adjust bias ((127-14)<<23)
+    m &= ~0x00800000; // Clear leading 1 bit
+    e +=  0x38800000; // Adjust bias ((127-14)<<23)
 
     return m | e; // Return combined number
 }