Browse code

hqdn3d: Fix out of array read in LOWPASS

CC:libav-stable@libav.org
Signed-off-by: Anton Khirnov <anton@khirnov.net>

Loren Merritt authored on 2012/09/22 08:43:16
Showing 2 changed files
... ...
@@ -37,10 +37,10 @@
37 37
 #include "vf_hqdn3d.h"
38 38
 
39 39
 #define LUT_BITS (depth==16 ? 8 : 4)
40
-#define RIGHTSHIFT(a,b) (((a)+(((1<<(b))-1)>>1))>>(b))
41
-#define LOAD(x) ((depth==8 ? src[x] : AV_RN16A(src+(x)*2)) << (16-depth))
42
-#define STORE(x,val) (depth==8 ? dst[x] = RIGHTSHIFT(val, 16-depth)\
43
-                    : AV_WN16A(dst+(x)*2, RIGHTSHIFT(val, 16-depth)))
40
+#define LOAD(x) (((depth == 8 ? src[x] : AV_RN16A(src + (x) * 2)) << (16 - depth))\
41
+                 + (((1 << (16 - depth)) - 1) >> 1))
42
+#define STORE(x,val) (depth == 8 ? dst[x] = (val) >> (16 - depth) : \
43
+                                   AV_WN16A(dst + (x) * 2, (val) >> (16 - depth)))
44 44
 
45 45
 av_always_inline
46 46
 static uint32_t lowpass(int prev, int cur, int16_t *coef, int depth)
... ...
@@ -39,6 +39,7 @@ SECTION .text
39 39
 %endif
40 40
 %if %3 != 16
41 41
     shl    %1, 16-%3
42
+    add    %1, (1<<(15-%3))-1
42 43
 %endif
43 44
 %endmacro
44 45
 
... ...
@@ -86,7 +87,6 @@ ALIGN 16
86 86
     mov       [frameantq+xq*2], t0w
87 87
     movifnidn dstq, dstmp
88 88
 %if %1 != 16
89
-    add    t0d, (1<<(15-%1))-1
90 89
     shr    t0d, 16-%1 ; could eliminate this by storing from t0h, but only with some contraints on register allocation
91 90
 %endif
92 91
 %if %1 == 8