]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Remove ->error of struct mp4.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 18 Aug 2021 16:08:38 +0000 (18:08 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
It's easier to have track_add(), the only function which sets ->error,
return an integer error code instead. Since track_add() is simple
and is only called by parse_sub_atoms(), open-code the logic there.

Also, don't reset ->total_tracks on errors because this leads to a
memory leak, don't increase the track counter on errors and remove
the comment which only states what is obvious.

mp4.c

diff --git a/mp4.c b/mp4.c
index c40fbe0b6cce2e1e7a87436b941555d7d780176b..477b4307244731a0702599c8e49cf2a89862efa3 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -52,11 +52,8 @@ struct mp4 {
        uint8_t last_atom;
        uint64_t file_size;
 
-       uint32_t error;
-
        /* incremental track index while reading the file */
        int32_t total_tracks;
-
        /* track data */
        struct mp4_track *track[MAX_TRACKS];
 
@@ -445,18 +442,6 @@ static int32_t set_position(struct mp4 *f, int64_t position)
        return 0;
 }
 
-static void track_add(struct mp4 *f)
-{
-       f->total_tracks++;
-
-       if (f->total_tracks > MAX_TRACKS) {
-               f->total_tracks = 0;
-               f->error++;
-               return;
-       }
-       f->track[f->total_tracks - 1] = para_calloc(sizeof(struct mp4_track));
-}
-
 static int read_stsz(struct mp4 *f)
 {
        int ret;
@@ -904,11 +889,13 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, int meta_only)
                if (size == 0)
                        return -1;
                counted_size += size;
-               /* we're starting to read a new track, update index,
-                * so that all data and tables get written in the right place
-                */
-               if (atom_type == ATOM_TRAK)
-                       track_add(f);
+               if (atom_type == ATOM_TRAK) {
+                       if (f->total_tracks >= MAX_TRACKS)
+                               return -1;
+                       f->total_tracks++;
+                       f->track[f->total_tracks - 1] = para_calloc(
+                               sizeof(struct mp4_track));
+               }
                /* parse subatoms */
                if (meta_only && !need_parse_when_meta_only(atom_type)) {
                        set_position(f, get_position(f) + size - header_size);
@@ -966,7 +953,7 @@ struct mp4 *mp4_open_read(const struct mp4_callback *cb)
 
        f->cb = cb;
        ret = parse_atoms(f, 0);
-       if (ret < 0 || f->error) {
+       if (ret < 0) {
                free(f);
                return NULL;
        }
@@ -1168,7 +1155,7 @@ struct mp4 *mp4_open_meta(const struct mp4_callback *cb)
 
        f->cb = cb;
        ret = parse_atoms(f, 1);
-       if (ret < 0 || f->error) {
+       if (ret < 0) {
                free(f);
                return NULL;
        }