]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpl2dec.c
avformat: Constify all muxer/demuxers
[ffmpeg] / libavformat / mpl2dec.c
index dfcdf5a5645a7c6c881bead6f0435bef68051fa7..b99acff157aa9969bc3876949884e3d513a142cc 100644 (file)
@@ -33,7 +33,7 @@ typedef struct {
     FFDemuxSubtitlesQueue q;
 } MPL2Context;
 
-static int mpl2_probe(AVProbeData *p)
+static int mpl2_probe(const AVProbeData *p)
 {
     int i;
     char c;
@@ -55,7 +55,7 @@ static int mpl2_probe(AVProbeData *p)
     return AVPROBE_SCORE_MAX;
 }
 
-static int read_ts(char **line, int64_t *pts_start, int *duration)
+static int read_ts(char **line, int64_t *pts_start, int64_t *duration)
 {
     char c;
     int len;
@@ -69,7 +69,10 @@ static int read_ts(char **line, int64_t *pts_start, int *duration)
     }
     if (sscanf(*line, "[%"SCNd64"][%"SCNd64"]%c%n",
                pts_start, &end, &c, &len) >= 3) {
-        *duration = end - *pts_start;
+        if (end < *pts_start || end - (uint64_t)*pts_start > INT64_MAX) {
+            *duration = -1;
+        } else
+            *duration = end - *pts_start;
         *line += len - 1;
         return 0;
     }
@@ -80,7 +83,6 @@ static int mpl2_read_header(AVFormatContext *s)
 {
     MPL2Context *mpl2 = s->priv_data;
     AVStream *st = avformat_new_stream(s, NULL);
-    int res = 0;
 
     if (!st)
         return AVERROR(ENOMEM);
@@ -97,7 +99,7 @@ static int mpl2_read_header(AVFormatContext *s)
         const int64_t pos = avio_tell(s->pb);
         int len = ff_get_line(s->pb, line, sizeof(line));
         int64_t pts_start;
-        int duration;
+        int64_t duration;
 
         if (!len)
             break;
@@ -108,8 +110,10 @@ static int mpl2_read_header(AVFormatContext *s)
             AVPacket *sub;
 
             sub = ff_subtitles_queue_insert(&mpl2->q, p, strlen(p), 0);
-            if (!sub)
+            if (!sub) {
+                ff_subtitles_queue_clean(&mpl2->q);
                 return AVERROR(ENOMEM);
+            }
             sub->pos = pos;
             sub->pts = pts_start;
             sub->duration = duration;
@@ -117,7 +121,7 @@ static int mpl2_read_header(AVFormatContext *s)
     }
 
     ff_subtitles_queue_finalize(s, &mpl2->q);
-    return res;
+    return 0;
 }
 
 static int mpl2_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -141,7 +145,7 @@ static int mpl2_read_close(AVFormatContext *s)
     return 0;
 }
 
-AVInputFormat ff_mpl2_demuxer = {
+const AVInputFormat ff_mpl2_demuxer = {
     .name           = "mpl2",
     .long_name      = NULL_IF_CONFIG_SMALL("MPL2 subtitles"),
     .priv_data_size = sizeof(MPL2Context),