Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/4] avcodec/mpegvideo_enc: Use av_unreachable() for unreachable code
@ 2025-05-21 12:44 Andreas Rheinhardt
  2025-05-24  2:33 ` Andreas Rheinhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-05-21 12:44 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 29 bytes --]

Patches attached.

- Andreas

[-- Attachment #2: 0001-avcodec-mpegvideo_enc-Use-av_unreachable-for-unreach.patch --]
[-- Type: text/x-patch, Size: 1928 bytes --]

From 8be9ae98dd8c880dd459cddb3192c67294d25186 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 16 May 2025 16:43:34 +0200
Subject: [PATCH 1/4] avcodec/mpegvideo_enc: Use av_unreachable() for
 unreachable code

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpegvideo_enc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6e9533ebc9..0023e88dc1 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -559,9 +559,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
     case AV_PIX_FMT_YUV422P:
         s->c.chroma_format = CHROMA_422;
         break;
+    default:
+        av_unreachable("Already checked via CODEC_PIXFMTS");
     case AV_PIX_FMT_YUVJ420P:
     case AV_PIX_FMT_YUV420P:
-    default:
         s->c.chroma_format = CHROMA_420;
         break;
     }
@@ -992,7 +993,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         s->c.low_delay         = 1;
         break;
     default:
-        return AVERROR(EINVAL);
+        av_unreachable("List contains all codecs using ff_mpv_encode_init()");
     }
 
     avctx->has_b_frames = !s->c.low_delay;
@@ -3541,7 +3542,10 @@ static int encode_thread(AVCodecContext *c, void *arg){
                     }
                     break;
                 default:
-                    av_log(s->c.avctx, AV_LOG_ERROR, "illegal MB type\n");
+                    av_unreachable("There is a case for every CANDIDATE_MB_TYPE_* "
+                                   "except CANDIDATE_MB_TYPE_SKIPPED which is never "
+                                   "the only candidate (always coupled with INTER) "
+                                   "so that it never reaches this switch");
                 }
 
                 encode_mb(s, motion_x, motion_y);
-- 
2.45.2


[-- Attachment #3: 0002-avcodec-msmpeg4dec-Use-av_unreachable-for-unreachabl.patch --]
[-- Type: text/x-patch, Size: 1681 bytes --]

From c3bbb56ba29fa89bcb5732f263f127d15124fba2 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 16 May 2025 18:24:38 +0200
Subject: [PATCH 2/4] avcodec/msmpeg4dec: Use av_unreachable() for unreachable
 code

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/msmpeg4dec.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index df67d43542..ddb990b1a0 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -379,6 +379,8 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
         break;
     case MSMP4_WMV2:
         break;
+    default:
+        av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
     }
 
     s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe
@@ -472,6 +474,8 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
             ms->dc_table_index = get_bits1(&s->gb);
             s->inter_intra_pred= 0;
             break;
+        default:
+            av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
         }
         s->no_rounding = 1;
         if(s->avctx->debug&FF_DEBUG_PICT_INFO)
@@ -523,6 +527,8 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
             s->inter_intra_pred = s->width*s->height < 320*240 &&
                                   ms->bit_rate <= II_BITRATE;
             break;
+        default:
+            av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
         }
 
         if(s->avctx->debug&FF_DEBUG_PICT_INFO)
-- 
2.45.2


[-- Attachment #4: 0003-avcodec-h263dec-Use-av_unreachable-for-unreachable-c.patch --]
[-- Type: text/x-patch, Size: 1010 bytes --]

From 3619f0f736bf91c45fea89dee81bbf97663d0a4d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 16 May 2025 18:38:41 +0200
Subject: [PATCH 3/4] avcodec/h263dec: Use av_unreachable() for unreachable
 code

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h263dec.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index c36070e23c..eb4c48f68c 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -150,9 +150,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
         s->h263_flv = 1;
         break;
     default:
-        av_log(avctx, AV_LOG_ERROR, "Unsupported codec %d\n",
-               avctx->codec->id);
-        return AVERROR(ENOSYS);
+        av_unreachable("Switch contains a case for every codec using ff_h263_decode_init()");
     }
 
     if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
-- 
2.45.2


[-- Attachment #5: 0004-avcodec-pcm-Use-av_unreachable-for-unreachable-code.patch --]
[-- Type: text/x-patch, Size: 898 bytes --]

From 4ca5d0fa3587e1de7d698e16d7eea7c98d432fdf Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 21 May 2025 12:55:48 +0200
Subject: [PATCH 4/4] avcodec/pcm: Use av_unreachable() for unreachable code

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/pcm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index bff61f2195..68b1945194 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -327,6 +327,8 @@ static av_cold av_unused int pcm_lut_decode_init(AVCodecContext *avctx)
     PCMLUTDecode *s = avctx->priv_data;
 
     switch (avctx->codec_id) {
+    default:
+        av_unreachable("pcm_lut_decode_init() only used with alaw, mulaw and vidc");
     case AV_CODEC_ID_PCM_ALAW:
         for (int i = 0; i < 256; i++)
             s->table[i] = alaw2linear(i);
-- 
2.45.2


[-- Attachment #6: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/4] avcodec/mpegvideo_enc: Use av_unreachable() for unreachable code
  2025-05-21 12:44 [FFmpeg-devel] [PATCH 1/4] avcodec/mpegvideo_enc: Use av_unreachable() for unreachable code Andreas Rheinhardt
@ 2025-05-24  2:33 ` Andreas Rheinhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-05-24  2:33 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> Patches attached.
> 
> - Andreas
> 
Will apply this patchset tonight unless there are objections.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-05-24  2:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-21 12:44 [FFmpeg-devel] [PATCH 1/4] avcodec/mpegvideo_enc: Use av_unreachable() for unreachable code Andreas Rheinhardt
2025-05-24  2:33 ` Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git