shithub: dav1d

Download patch

ref: 65b41008e4fbe9b10f116c03569651e896709811
parent: deab25342b5361df0d5aa2f8f9d38301c0146ab3
author: Ronald S. Bultje <rsbultje@gmail.com>
date: Fri Sep 28 08:01:54 EDT 2018

Workaround two more ubsan warnings.

Fixes #27 as well as another one mentioned in the wiki task-list.

--- a/src/env.h
+++ b/src/env.h
@@ -408,13 +408,13 @@
     int cnt[2] = { 0 };
 
     if (have_top && !a->intra[xb4]) {
-        if (a->ref[0][xb4] - 2U < 2) cnt[a->ref[0][xb4] - 2]++;
-        if (a->comp_type[xb4] && a->ref[1][xb4] - 2U < 2) cnt[a->ref[1][xb4] - 2]++;
+        if ((a->ref[0][xb4] ^ 2U) < 2) cnt[a->ref[0][xb4] - 2]++;
+        if (a->comp_type[xb4] && (a->ref[1][xb4] ^ 2U) < 2) cnt[a->ref[1][xb4] - 2]++;
     }
 
     if (have_left && !l->intra[yb4]) {
-        if (l->ref[0][yb4] - 2U < 2) cnt[l->ref[0][yb4] - 2]++;
-        if (l->comp_type[yb4] && l->ref[1][yb4] - 2U < 2) cnt[l->ref[1][yb4] - 2]++;
+        if ((l->ref[0][yb4] ^ 2U) < 2) cnt[l->ref[0][yb4] - 2]++;
+        if (l->comp_type[yb4] && (l->ref[1][yb4] ^ 2U) < 2) cnt[l->ref[1][yb4] - 2]++;
     }
 
     return cnt[0] == cnt[1] ? 1 : cnt[0] < cnt[1] ? 0 : 2;
--- a/src/lf_mask.c
+++ b/src/lf_mask.c
@@ -111,13 +111,17 @@
         for (y = 0; y < h4; y++) {
             int ltx = txa[0][0][y][0];
             int step = txa[0][1][y][0];
-            for (x = step, mask = 1U << (bx4 + step);
-                 x < w4; x += step, mask <<= step)
-            {
-                const int rtx = txa[0][0][y][x];
-                masks[0][by4 + y][imin(rtx, ltx)] |= mask;
-                ltx = rtx;
-                step = txa[0][1][y][x];
+            if (step < w4) {
+                x = step;
+                mask = 1U << (bx4 + step);
+                do {
+                    const int rtx = txa[0][0][y][x];
+                    masks[0][by4 + y][imin(rtx, ltx)] |= mask;
+                    ltx = rtx;
+                    step = txa[0][1][y][x];
+                    x += step;
+                    mask <<= step;
+                } while (x < w4);
             }
         }