]> granicus.if.org Git - libvpx/commitdiff
quantize: silence unsigned overflow warning
authorJohann <johannkoenig@google.com>
Tue, 15 Aug 2017 16:48:24 +0000 (09:48 -0700)
committerJohann <johannkoenig@google.com>
Tue, 15 Aug 2017 16:48:24 +0000 (09:48 -0700)
The result of the xor operation is unsigned. If coeff was negative,
this results in an unsigned value - INT_MIN.

Change-Id: I1f1edeaa6de1f4c68b848e8a82a666d390b749f0

vpx_dsp/quantize.c

index 3c7f9832f7adc09fe6cd2fc3d6c273cdd5c67618..00fa4dc82fc4f70a03b0b874e768f446b0b1b3e6 100644 (file)
@@ -203,7 +203,9 @@ void vpx_highbd_quantize_b_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
         const int64_t tmp2 = ((tmp1 * quant_ptr[rc != 0]) >> 16) + tmp1;
         const uint32_t abs_qcoeff =
             (uint32_t)((tmp2 * quant_shift_ptr[rc != 0]) >> 16);
-        qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
+        // Restoring the sign triggers unsigned overflow warnings with negative
+        // values because the result of the xor operation is unsigned.
+        qcoeff_ptr[rc] = (tran_low_t)(abs_qcoeff ^ coeff_sign) - coeff_sign;
         dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0];
         if (abs_qcoeff) eob = i;
       }
@@ -310,7 +312,7 @@ void vpx_highbd_quantize_b_32x32_c(
       const int64_t tmp2 = ((tmp1 * quant_ptr[rc != 0]) >> 16) + tmp1;
       const uint32_t abs_qcoeff =
           (uint32_t)((tmp2 * quant_shift_ptr[rc != 0]) >> 15);
-      qcoeff_ptr[rc] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
+      qcoeff_ptr[rc] = (tran_low_t)(abs_qcoeff ^ coeff_sign) - coeff_sign;
       dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0] / 2;
       if (abs_qcoeff) eob = idx_arr[i];
     }