diff mbox

[FFmpeg-devel,5/8] avformat/matroskadec: Simplify control flow of parsing laces

Message ID 20191203170910.5310-5-andreas.rheinhardt@gmail.com
State Accepted
Commit a69f92a94638984cfc1203a43184e662365ab953
Headers show

Commit Message

Andreas Rheinhardt Dec. 3, 2019, 5:09 p.m. UTC
Up until now, when an error happened in one of the inner loops in
matroska_parse_laces, a variable designated for the return value has
been set to an error value and break has been used to exit the
current loop/case. This was done so that the end of matroska_parse_laces
is reached, because said function allocated memory which is later used
and freed in the calling function and passed at the end of
matroska_parse_laces.

But given that there is no allocation any more, one can now return
immediately. And this commit does this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
Supersedes https://ffmpeg.org/pipermail/ffmpeg-devel/2019-August/248368.html

 libavformat/matroskadec.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
diff mbox

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 2f289a90b3..88c43ee0c1 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2992,7 +2992,7 @@  static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
                                 int *buf_size, int type,
                                 uint32_t lace_size[256], int *laces)
 {
-    int res = 0, n, size = *buf_size;
+    int n, size = *buf_size;
     uint8_t *data = *buf;
 
     if (!type) {
@@ -3011,13 +3011,12 @@  static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
     {
         uint8_t temp;
         uint32_t total = 0;
-        for (n = 0; res == 0 && n < *laces - 1; n++) {
+        for (n = 0; n < *laces - 1; n++) {
             lace_size[n] = 0;
 
             while (1) {
                 if (size <= total) {
-                    res = AVERROR_INVALIDDATA;
-                    break;
+                    return AVERROR_INVALIDDATA;
                 }
                 temp          = *data;
                 total        += temp;
@@ -3029,8 +3028,7 @@  static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
             }
         }
         if (size <= total) {
-            res = AVERROR_INVALIDDATA;
-            break;
+            return AVERROR_INVALIDDATA;
         }
 
         lace_size[n] = size - total;
@@ -3039,8 +3037,7 @@  static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
 
     case 0x2: /* fixed-size lacing */
         if (size % (*laces)) {
-            res = AVERROR_INVALIDDATA;
-            break;
+            return AVERROR_INVALIDDATA;
         }
         for (n = 0; n < *laces; n++)
             lace_size[n] = size / *laces;
@@ -3054,21 +3051,19 @@  static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
         if (n < 0 || num > INT_MAX) {
             av_log(matroska->ctx, AV_LOG_INFO,
                    "EBML block data error\n");
-            res = n<0 ? n : AVERROR_INVALIDDATA;
-            break;
+            return n < 0 ? n : AVERROR_INVALIDDATA;
         }
         data += n;
         size -= n;
         total = lace_size[0] = num;
-        for (n = 1; res == 0 && n < *laces - 1; n++) {
+        for (n = 1; n < *laces - 1; n++) {
             int64_t snum;
             int r;
             r = matroska_ebmlnum_sint(matroska, data, size, &snum);
             if (r < 0 || lace_size[n - 1] + snum > (uint64_t)INT_MAX) {
                 av_log(matroska->ctx, AV_LOG_INFO,
                        "EBML block data error\n");
-                res = r<0 ? r : AVERROR_INVALIDDATA;
-                break;
+                return r < 0 ? r : AVERROR_INVALIDDATA;
             }
             data        += r;
             size        -= r;
@@ -3076,8 +3071,7 @@  static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
             total       += lace_size[n];
         }
         if (size <= total) {
-            res = AVERROR_INVALIDDATA;
-            break;
+            return AVERROR_INVALIDDATA;
         }
         lace_size[*laces - 1] = size - total;
         break;
@@ -3087,7 +3081,7 @@  static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
     *buf      = data;
     *buf_size = size;
 
-    return res;
+    return 0;
 }
 
 static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska,