]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/icodec.c
avformat: Constify all muxer/demuxers
[ffmpeg] / libavformat / icodec.c
index c061f3ec421308e96169310e4ead67e29d8edf64..9349582ffc716e46b8271ba69a4e8d924a21efce 100644 (file)
@@ -84,6 +84,9 @@ static int read_header(AVFormatContext *s)
     avio_skip(pb, 4);
     ico->nb_images = avio_rl16(pb);
 
+    if (!ico->nb_images)
+        return AVERROR_INVALIDDATA;
+
     ico->images = av_malloc_array(ico->nb_images, sizeof(IcoImage));
     if (!ico->images)
         return AVERROR(ENOMEM);
@@ -93,7 +96,7 @@ static int read_header(AVFormatContext *s)
         int tmp;
 
         if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0)
-            break;
+            goto fail;
 
         st = avformat_new_stream(s, NULL);
         if (!st) {
@@ -113,13 +116,12 @@ static int read_header(AVFormatContext *s)
         ico->images[i].size   = avio_rl32(pb);
         if (ico->images[i].size <= 0) {
             av_log(s, AV_LOG_ERROR, "Invalid image size %d\n", ico->images[i].size);
-            av_freep(&ico->images);
-            return AVERROR_INVALIDDATA;
+            goto fail;
         }
         ico->images[i].offset = avio_rl32(pb);
 
         if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0)
-            break;
+            goto fail;
 
         codec = avio_rl32(pb);
         switch (codec) {
@@ -130,8 +132,7 @@ static int read_header(AVFormatContext *s)
             break;
         case 40:
             if (ico->images[i].size < 40) {
-                av_freep(&ico->images);
-                return AVERROR_INVALIDDATA;
+                goto fail;
             }
             st->codecpar->codec_id = AV_CODEC_ID_BMP;
             tmp = avio_rl32(pb);
@@ -143,12 +144,14 @@ static int read_header(AVFormatContext *s)
             break;
         default:
             avpriv_request_sample(s, "codec %d", codec);
-            av_freep(&ico->images);
-            return AVERROR_INVALIDDATA;
+            goto fail;
         }
     }
 
     return 0;
+fail:
+    av_freep(&ico->images);
+    return AVERROR_INVALIDDATA;
 }
 
 static int read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -217,7 +220,7 @@ static int ico_read_close(AVFormatContext * s)
     return 0;
 }
 
-AVInputFormat ff_ico_demuxer = {
+const AVInputFormat ff_ico_demuxer = {
     .name           = "ico",
     .long_name      = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"),
     .priv_data_size = sizeof(IcoDemuxContext),