[FFmpeg-cvslog] lavc: fix bitshifts amount bigger than the type

Vittorio Giovara git at videolan.org
Sun Jan 18 02:50:10 CET 2015


ffmpeg | branch: release/2.4 | Vittorio Giovara <vittorio.giovara at gmail.com> | Mon Nov 17 00:22:27 2014 +0100| [61fdbf7ff64c0ae1bdd6a8d573092dc6924c1dba] | committer: Luca Barbato

lavc: fix bitshifts amount bigger than the type

CC: libav-stable at libav.org
Bug-Id: CID 1194387 / CID 1194389 / CID 1194393 / CID 1206638
(cherry picked from commit 85dc006b1a829726dd5e3a9b0fcc6a1dbfe6dffa)
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=61fdbf7ff64c0ae1bdd6a8d573092dc6924c1dba
---

 libavcodec/cavs.c     |    5 +++--
 libavcodec/cavsdec.c  |    4 ++--
 libavcodec/dnxhdenc.c |    2 +-
 libavcodec/internal.h |    2 ++
 libavcodec/vp8.c      |    4 ++--
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 2be50a7..788fcad 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -30,6 +30,7 @@
 #include "golomb.h"
 #include "h264chroma.h"
 #include "idctdsp.h"
+#include "internal.h"
 #include "mathops.h"
 #include "qpeldsp.h"
 #include "cavs.h"
@@ -529,8 +530,8 @@ static inline void scale_mv(AVSContext *h, int *d_x, int *d_y,
 {
     int den = h->scale_den[src->ref];
 
-    *d_x = (src->x * distp * den + 256 + (src->x >> 31)) >> 9;
-    *d_y = (src->y * distp * den + 256 + (src->y >> 31)) >> 9;
+    *d_x = (src->x * distp * den + 256 + FF_SIGNBIT(src->x)) >> 9;
+    *d_y = (src->y * distp * den + 256 + FF_SIGNBIT(src->y)) >> 9;
 }
 
 static inline void mv_pred_median(AVSContext *h,
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index fbbd048..a091eeb 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -473,7 +473,7 @@ static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
 {
     cavs_vector *pmv_bw = pmv_fw + MV_BWD_OFFS;
     int den = h->direct_den[col_mv->ref];
-    int m = col_mv->x >> 31;
+    int m = FF_SIGNBIT(col_mv->x);
 
     pmv_fw->dist = h->dist[1];
     pmv_bw->dist = h->dist[0];
@@ -482,7 +482,7 @@ static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
     /* scale the co-located motion vector according to its temporal span */
     pmv_fw->x =     (((den + (den * col_mv->x * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
     pmv_bw->x = m - (((den + (den * col_mv->x * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
-    m = col_mv->y >> 31;
+    m = FF_SIGNBIT(col_mv->y);
     pmv_fw->y =     (((den + (den * col_mv->y * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
     pmv_bw->y = m - (((den + (den * col_mv->y * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
 }
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 4294510..6896fc1 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -108,7 +108,7 @@ static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block,
 
     for (i = 1; i < 64; ++i) {
         int j = scantable[i];
-        int sign = block[j] >> 31;
+        int sign = FF_SIGNBIT(block[j]);
         int level = (block[j] ^ sign) - sign;
         level = level * qmat[j] >> DNX10BIT_QMAT_SHIFT;
         block[j] = (level ^ sign) - sign;
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 3b2ae40..a68d613 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -35,6 +35,8 @@
 
 #define FF_SANE_NB_CHANNELS 63U
 
+#define FF_SIGNBIT(x) (x >> CHAR_BIT * sizeof(x) - 1)
+
 typedef struct FramePool {
     /**
      * Pools for each data plane. For audio all the planes have the same size,
diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c
index 5426555..ce9d3cf 100644
--- a/libavcodec/vp8.c
+++ b/libavcodec/vp8.c
@@ -1882,8 +1882,8 @@ void inter_predict(VP8Context *s, VP8ThreadData *td, uint8_t *dst[3],
                          mb->bmv[2 * y       * 4 + 2 * x + 1].y +
                          mb->bmv[(2 * y + 1) * 4 + 2 * x    ].y +
                          mb->bmv[(2 * y + 1) * 4 + 2 * x + 1].y;
-                uvmv.x = (uvmv.x + 2 + (uvmv.x >> (INT_BIT - 1))) >> 2;
-                uvmv.y = (uvmv.y + 2 + (uvmv.y >> (INT_BIT - 1))) >> 2;
+                uvmv.x = (uvmv.x + 2 + FF_SIGNBIT(uvmv.x)) >> 2;
+                uvmv.y = (uvmv.y + 2 + FF_SIGNBIT(uvmv.y)) >> 2;
                 if (s->profile == 3) {
                     uvmv.x &= ~7;
                     uvmv.y &= ~7;



More information about the ffmpeg-cvslog mailing list