]> git.sesse.net Git - ffmpeg/commitdiff
libavformat/ffmetadec.c: Fix Use-of-uninitialized-value
authorThierry Foucu <tfoucu@gmail.com>
Thu, 20 Aug 2020 19:14:52 +0000 (12:14 -0700)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 22 Aug 2020 20:51:07 +0000 (22:51 +0200)
Check the return value of sscanf as it can return -1(EOF), for example
when the first char in the line is 0x00

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/ffmetadec.c

index 45c92f1ff6c82f2099ebaa0852c49fd4872f4bb0..0ea89fe3f346bc32dee191cb4887835632edbcc2 100644 (file)
@@ -101,19 +101,22 @@ static AVChapter *read_chapter(AVFormatContext *s)
     uint8_t line[256];
     int64_t start, end;
     AVRational tb = {1, 1e9};
+    int ret;
 
     get_line(s->pb, line, sizeof(line));
 
     if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den))
         get_line(s->pb, line, sizeof(line));
-    if (!sscanf(line, "START=%"SCNd64, &start)) {
+    ret = sscanf(line, "START=%"SCNd64, &start);
+    if (ret <= 0) {
         av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line);
         start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ?
                  s->chapters[s->nb_chapters - 1]->end : 0;
     } else
         get_line(s->pb, line, sizeof(line));
 
-    if (!sscanf(line, "END=%"SCNd64, &end)) {
+    ret = sscanf(line, "END=%"SCNd64, &end);
+    if (ret <= 0) {
         av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line);
         end = AV_NOPTS_VALUE;
     }