[FFmpeg-devel] [PATCH] lavu: make av_get_media_type_string() never return NULL

Scott Theisen scott.the.elm at gmail.com
Wed Feb 2 00:30:58 EET 2022


printf %s with a null pointer is undefined behavior
---
 libavutil/avutil.h | 3 +--
 libavutil/utils.c  | 3 ++-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 4d633156d1..4bd468d72f 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -207,8 +207,7 @@ enum AVMediaType {
 };
 
 /**
- * Return a string describing the media_type enum, NULL if media_type
- * is unknown.
+ * Return a string describing the media_type enum, never NULL.
  */
 const char *av_get_media_type_string(enum AVMediaType media_type);
 
diff --git a/libavutil/utils.c b/libavutil/utils.c
index ea9b5097b8..c85d7abace 100644
--- a/libavutil/utils.c
+++ b/libavutil/utils.c
@@ -71,12 +71,13 @@ const char *avutil_license(void)
 const char *av_get_media_type_string(enum AVMediaType media_type)
 {
     switch (media_type) {
+    case AVMEDIA_TYPE_UNKNOWN:    return "unknown";
     case AVMEDIA_TYPE_VIDEO:      return "video";
     case AVMEDIA_TYPE_AUDIO:      return "audio";
     case AVMEDIA_TYPE_DATA:       return "data";
     case AVMEDIA_TYPE_SUBTITLE:   return "subtitle";
     case AVMEDIA_TYPE_ATTACHMENT: return "attachment";
-    default:                      return NULL;
+    default:                      return "invalid";
     }
 }
 
-- 
2.32.0



More information about the ffmpeg-devel mailing list