OSDN Git Service

dnxhdenc: fixed signed multiplication overflow
authorMans Rullgard <mans@mansr.com>
Sat, 8 Oct 2011 00:37:20 +0000 (01:37 +0100)
committerMans Rullgard <mans@mansr.com>
Fri, 14 Oct 2011 19:45:22 +0000 (20:45 +0100)
The low 32 bits of a multiplication are the same for signed
and unsigned operands.  Casting to unsigned before multiplying
is thus equivalent while avoiding signed overflow, which is
undefined by the C99 standard.

Signed-off-by: Mans Rullgard <mans@mansr.com>
libavcodec/dnxhdenc.c

index db46085..89e5c08 100644 (file)
@@ -623,7 +623,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
         for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x, pix += 16) {
             unsigned mb  = mb_y * ctx->m.mb_width + mb_x;
             int sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize);
-            int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)(sum*sum))>>8)+128)>>8;
+            int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)sum*sum)>>8)+128)>>8;
             ctx->mb_cmp[mb].value = varc;
             ctx->mb_cmp[mb].mb = mb;
         }