[FFmpeg-devel] [PATCH 1/2] av(codec|device): Don't cast pointers to int

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Nov 20 18:32:56 EET 2021


C99/C11 6.3.2.3 5: "Any pointer type may be converted to an integer
type. [...] If the result cannot be represented in the integer type,
the behavior is undefined." So stop casting pointers to int; use
uintptr_t instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
When did these asserts actually help the last time?

 libavcodec/dvdec.c                     | 4 ++--
 libavcodec/x86/h264_qpel.c             | 8 ++++----
 libavcodec/x86/me_cmp_init.c           | 6 +++---
 libavcodec/x86/mpegvideoenc_template.c | 2 +-
 libavdevice/xcbgrab.c                  | 2 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index a7424fd1d4..b72a67d01c 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -399,8 +399,8 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg)
     int retried = 0;
     int sta;
 
-    av_assert1((((int) mb_bit_buffer) & 7) == 0);
-    av_assert1((((int) vs_bit_buffer) & 7) == 0);
+    av_assert1((((uintptr_t) mb_bit_buffer) & 7) == 0);
+    av_assert1((((uintptr_t) vs_bit_buffer) & 7) == 0);
 
 retry:
 
diff --git a/libavcodec/x86/h264_qpel.c b/libavcodec/x86/h264_qpel.c
index a2d8a64976..320d98933a 100644
--- a/libavcodec/x86/h264_qpel.c
+++ b/libavcodec/x86/h264_qpel.c
@@ -338,7 +338,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, const uin
     LOCAL_ALIGNED(ALIGN, uint8_t, temp, [SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
     uint8_t * const halfHV= temp;\
     int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
-    av_assert2(((int)temp & 7) == 0);\
+    av_assert2(((uintptr_t)temp & 7) == 0);\
     ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
     ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
 }\
@@ -348,7 +348,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, const uin
     LOCAL_ALIGNED(ALIGN, uint8_t, temp, [SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
     uint8_t * const halfHV= temp;\
     int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
-    av_assert2(((int)temp & 7) == 0);\
+    av_assert2(((uintptr_t)temp & 7) == 0);\
     ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
     ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
 }\
@@ -358,7 +358,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, const uin
     LOCAL_ALIGNED(ALIGN, uint8_t, temp, [SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
     uint8_t * const halfHV= temp;\
     int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
-    av_assert2(((int)temp & 7) == 0);\
+    av_assert2(((uintptr_t)temp & 7) == 0);\
     ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
     ff_ ## OPNAME ## pixels ## SIZE ## _l2_shift5_mmxext(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
 }\
@@ -368,7 +368,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, const uin
     LOCAL_ALIGNED(ALIGN, uint8_t, temp, [SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\
     uint8_t * const halfHV= temp;\
     int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
-    av_assert2(((int)temp & 7) == 0);\
+    av_assert2(((uintptr_t)temp & 7) == 0);\
     ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
     ff_ ## OPNAME ## pixels ## SIZE ## _l2_shift5_mmxext(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
 }\
diff --git a/libavcodec/x86/me_cmp_init.c b/libavcodec/x86/me_cmp_init.c
index 701eb1ab25..9af911bb88 100644
--- a/libavcodec/x86/me_cmp_init.c
+++ b/libavcodec/x86/me_cmp_init.c
@@ -131,7 +131,7 @@ static int vsad_intra16_mmx(MpegEncContext *v, uint8_t *pix, uint8_t *dummy,
 {
     int tmp;
 
-    av_assert2((((int) pix) & 7) == 0);
+    av_assert2(((uintptr_t) pix & 7) == 0);
     av_assert2((stride & 7) == 0);
 
 #define SUM(in0, in1, out0, out1)               \
@@ -195,8 +195,8 @@ static int vsad16_mmx(MpegEncContext *v, uint8_t *pix1, uint8_t *pix2,
 {
     int tmp;
 
-    av_assert2((((int) pix1) & 7) == 0);
-    av_assert2((((int) pix2) & 7) == 0);
+    av_assert2(((uintptr_t)pix1 & 7) == 0);
+    av_assert2(((uintptr_t)pix2 & 7) == 0);
     av_assert2((stride & 7) == 0);
 
 #define SUM(in0, in1, out0, out1)       \
diff --git a/libavcodec/x86/mpegvideoenc_template.c b/libavcodec/x86/mpegvideoenc_template.c
index b32b1b0350..30c06a6b2c 100644
--- a/libavcodec/x86/mpegvideoenc_template.c
+++ b/libavcodec/x86/mpegvideoenc_template.c
@@ -109,7 +109,7 @@ static int RENAME(dct_quantize)(MpegEncContext *s,
     const uint16_t *qmat, *bias;
     LOCAL_ALIGNED_16(int16_t, temp_block, [64]);
 
-    av_assert2((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly?
+    av_assert2((7&(uintptr_t)(&temp_block[0])) == 0); //did gcc align it correctly?
 
     //s->fdct (block);
     RENAME_FDCT(ff_fdct)(block); // cannot be anything else ...
diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c
index 8164101c5e..64a68ba497 100644
--- a/libavdevice/xcbgrab.c
+++ b/libavdevice/xcbgrab.c
@@ -277,7 +277,7 @@ static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
         av_log(s, AV_LOG_ERROR, "Could not get shared memory buffer.\n");
         return AVERROR(ENOMEM);
     }
-    segment = (xcb_shm_seg_t)av_buffer_pool_buffer_get_opaque(buf);
+    segment = (xcb_shm_seg_t)(uintptr_t)av_buffer_pool_buffer_get_opaque(buf);
 
     iq = xcb_shm_get_image(c->conn, drawable,
                            c->x, c->y, c->width, c->height, ~0,
-- 
2.30.2



More information about the ffmpeg-devel mailing list