]> granicus.if.org Git - libvpx/commitdiff
rd_pick_inter_mode: prevent signed integer overflow
authorJames Zern <jzern@google.com>
Tue, 6 Nov 2012 01:14:32 +0000 (17:14 -0800)
committerJames Zern <jzern@google.com>
Tue, 6 Nov 2012 01:14:32 +0000 (17:14 -0800)
calculate the txfm_cache difference first as both values may be
INT64_MAX with the intent that they cancel each other out.

Change-Id: I214d072458e1b24f60289974e6302af1aff7b66c

vp9/encoder/rdopt.c

index ffff248acc0377c83d3bd5b981356198cbebf1fd..d0f905b1d6430a299f8d3e993a3d73487d897d2f 100644 (file)
@@ -4090,7 +4090,9 @@ static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
         for (i = 0; i < NB_TXFM_MODES; i++) {
           int64_t adj_rd;
           if (this_mode != B_PRED) {
-            adj_rd = this_rd + txfm_cache[i] - txfm_cache[cm->txfm_mode];
+            const int64_t txfm_mode_diff =
+                txfm_cache[i] - txfm_cache[cm->txfm_mode];
+            adj_rd = this_rd + txfm_mode_diff;
           } else {
             adj_rd = this_rd;
           }