[FFmpeg-devel] [PATCH 3/4] avcodec/decoders: Use const uint8_t* to access input packet data

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Jul 4 14:02:42 EEST 2022


These packets need not be writable, so we must not modify them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/ansi.c           | 2 +-
 libavcodec/cllc.c           | 2 +-
 libavcodec/diracdec.c       | 2 +-
 libavcodec/fic.c            | 8 ++++----
 libavcodec/hqx.c            | 2 +-
 libavcodec/hqx.h            | 2 +-
 libavcodec/libdavs2.c       | 2 +-
 libavcodec/libjxldec.c      | 2 +-
 libavcodec/libopenjpegdec.c | 2 +-
 libavcodec/msrle.c          | 2 +-
 libavcodec/mwsc.c           | 2 +-
 libavcodec/v410dec.c        | 4 ++--
 libavcodec/y41pdec.c        | 2 +-
 13 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/ansi.c b/libavcodec/ansi.c
index 909ebe7396..ff4437cc61 100644
--- a/libavcodec/ansi.c
+++ b/libavcodec/ansi.c
@@ -358,7 +358,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                         int *got_frame, AVPacket *avpkt)
 {
     AnsiContext *s = avctx->priv_data;
-    uint8_t *buf = avpkt->data;
+    const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     const uint8_t *buf_end   = buf+buf_size;
     int ret, i, count;
diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c
index f7283ca4f8..4866c5b2d4 100644
--- a/libavcodec/cllc.c
+++ b/libavcodec/cllc.c
@@ -359,7 +359,7 @@ static int cllc_decode_frame(AVCodecContext *avctx, AVFrame *pic,
                              int *got_picture_ptr, AVPacket *avpkt)
 {
     CLLCContext *ctx = avctx->priv_data;
-    uint8_t *src = avpkt->data;
+    const uint8_t *src = avpkt->data;
     uint32_t info_tag, info_offset;
     int data_size;
     GetBitContext gb;
diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index 9f3c930913..50d1d2e1d3 100644
--- a/libavcodec/diracdec.c
+++ b/libavcodec/diracdec.c
@@ -2264,7 +2264,7 @@ static int dirac_decode_frame(AVCodecContext *avctx, AVFrame *picture,
                               int *got_frame, AVPacket *pkt)
 {
     DiracContext *s     = avctx->priv_data;
-    uint8_t *buf        = pkt->data;
+    const uint8_t *buf  = pkt->data;
     int buf_size        = pkt->size;
     int i, buf_idx      = 0;
     int ret;
diff --git a/libavcodec/fic.c b/libavcodec/fic.c
index e56a1a323c..491f63ea0c 100644
--- a/libavcodec/fic.c
+++ b/libavcodec/fic.c
@@ -32,7 +32,7 @@
 
 typedef struct FICThreadContext {
     DECLARE_ALIGNED(16, int16_t, block)[64];
-    uint8_t *src;
+    const uint8_t *src;
     int slice_h;
     int src_size;
     int y_off;
@@ -174,7 +174,7 @@ static int fic_decode_slice(AVCodecContext *avctx, void *tdata)
     FICContext *ctx        = avctx->priv_data;
     FICThreadContext *tctx = tdata;
     GetBitContext gb;
-    uint8_t *src = tctx->src;
+    const uint8_t *src = tctx->src;
     int slice_h  = tctx->slice_h;
     int src_size = tctx->src_size;
     int y_off    = tctx->y_off;
@@ -271,14 +271,14 @@ static int fic_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                             int *got_frame, AVPacket *avpkt)
 {
     FICContext *ctx = avctx->priv_data;
-    uint8_t *src = avpkt->data;
+    const uint8_t *src = avpkt->data;
     int ret;
     int slice, nslices;
     int msize;
     int tsize;
     int cur_x, cur_y;
     int skip_cursor = ctx->skip_cursor;
-    uint8_t *sdata;
+    const uint8_t *sdata;
 
     if ((ret = ff_reget_buffer(avctx, ctx->frame, 0)) < 0)
         return ret;
diff --git a/libavcodec/hqx.c b/libavcodec/hqx.c
index c41fe61387..596b8a7ed3 100644
--- a/libavcodec/hqx.c
+++ b/libavcodec/hqx.c
@@ -404,7 +404,7 @@ static int hqx_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                             int *got_picture_ptr, AVPacket *avpkt)
 {
     HQXContext *ctx = avctx->priv_data;
-    uint8_t *src = avpkt->data;
+    const uint8_t *src = avpkt->data;
     uint32_t info_tag;
     int data_start;
     int i, ret;
diff --git a/libavcodec/hqx.h b/libavcodec/hqx.h
index 3eddaafb29..155ec7f84f 100644
--- a/libavcodec/hqx.h
+++ b/libavcodec/hqx.h
@@ -70,7 +70,7 @@ typedef struct HQXContext {
     int format, dcb, width, height;
     int interlaced;
 
-    uint8_t *src;
+    const uint8_t *src;
     unsigned int data_size;
     uint32_t slice_off[17];
 
diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c
index c2040775ae..918e48502c 100644
--- a/libavcodec/libdavs2.c
+++ b/libavcodec/libdavs2.c
@@ -190,7 +190,7 @@ static int davs2_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 {
     DAVS2Context *cad      = avctx->priv_data;
     int           buf_size = avpkt->size;
-    uint8_t      *buf_ptr  = avpkt->data;
+    const uint8_t *buf_ptr = avpkt->data;
     int           ret      = DAVS2_DEFAULT;
 
     /* end of stream, output what is still in the buffers */
diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index d516d3b0ac..829478bbde 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -321,7 +321,7 @@ static int libjxl_color_encoding_event(AVCodecContext *avctx, AVFrame *frame)
 static int libjxl_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
 {
     LibJxlDecodeContext *ctx = avctx->priv_data;
-    uint8_t *buf = avpkt->data;
+    const uint8_t *buf = avpkt->data;
     size_t remaining = avpkt->size;
     JxlDecoderStatus jret;
     int ret;
diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c
index 58715b43ee..58ac6c413a 100644
--- a/libavcodec/libopenjpegdec.c
+++ b/libavcodec/libopenjpegdec.c
@@ -321,7 +321,7 @@ static av_cold int libopenjpeg_decode_init(AVCodecContext *avctx)
 static int libopenjpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture,
                                     int *got_frame, AVPacket *avpkt)
 {
-    uint8_t *buf            = avpkt->data;
+    const uint8_t *buf      = avpkt->data;
     int buf_size            = avpkt->size;
     LibOpenJPEGContext *ctx = avctx->priv_data;
     const AVPixFmtDescriptor *desc;
diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c
index 041d0c9493..f9d7141c03 100644
--- a/libavcodec/msrle.c
+++ b/libavcodec/msrle.c
@@ -108,7 +108,7 @@ static int msrle_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
     if (avctx->height * istride == avpkt->size) { /* assume uncompressed */
         int linesize = av_image_get_linesize(avctx->pix_fmt, avctx->width, 0);
         uint8_t *ptr = s->frame->data[0];
-        uint8_t *buf = avpkt->data + (avctx->height-1)*istride;
+        const uint8_t *buf = avpkt->data + (avctx->height-1)*istride;
         int i, j;
 
         if (linesize < 0)
diff --git a/libavcodec/mwsc.c b/libavcodec/mwsc.c
index d89fbde4e2..499b220a07 100644
--- a/libavcodec/mwsc.c
+++ b/libavcodec/mwsc.c
@@ -92,7 +92,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 {
     MWSCContext *s = avctx->priv_data;
     z_stream *const zstream = &s->zstream.zstream;
-    uint8_t *buf = avpkt->data;
+    const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     GetByteContext gb;
     GetByteContext gbp;
diff --git a/libavcodec/v410dec.c b/libavcodec/v410dec.c
index f6d675c508..e67cb820ba 100644
--- a/libavcodec/v410dec.c
+++ b/libavcodec/v410dec.c
@@ -28,7 +28,7 @@
 
 typedef struct ThreadData {
     AVFrame *frame;
-    uint8_t *buf;
+    const uint8_t *buf;
     int stride;
 } ThreadData;
 
@@ -89,7 +89,7 @@ static int v410_decode_frame(AVCodecContext *avctx, AVFrame *pic,
                              int *got_frame, AVPacket *avpkt)
 {
     ThreadData td;
-    uint8_t *src = avpkt->data;
+    const uint8_t *src = avpkt->data;
     int ret;
     int thread_count = av_clip(avctx->thread_count, 1, avctx->height/4);
 
diff --git a/libavcodec/y41pdec.c b/libavcodec/y41pdec.c
index ca81dda0e8..4b1e64aff9 100644
--- a/libavcodec/y41pdec.c
+++ b/libavcodec/y41pdec.c
@@ -39,7 +39,7 @@ static av_cold int y41p_decode_init(AVCodecContext *avctx)
 static int y41p_decode_frame(AVCodecContext *avctx, AVFrame *pic,
                              int *got_frame, AVPacket *avpkt)
 {
-    uint8_t *src = avpkt->data;
+    const uint8_t *src = avpkt->data;
     uint8_t *y, *u, *v;
     int i, j, ret;
 
-- 
2.34.1



More information about the ffmpeg-devel mailing list