From 06dd900e86fee406c52f18b7dcf81f7487cb7cb6 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 13 Aug 2021 20:19:43 +0200 Subject: [PATCH] mp4: Simplify parse_tag(). We don't care about arbitrarily named tags, and those tags we're interested in are generally present in form of the standard tags (ATOM_TITLE, ATOM_ARTIST etc.). Since we now always call get_metadata_name() to get the string representation of the tag, we don't need to make a copy any more, just pass the const pointer directly to tag_add_field(). With this change in place it is obvious that we never pass a NULL or empty tag name to tag_add_field(), and we don't pass a NULL pointer for the value argument either, so remove the safety check. --- mp4.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/mp4.c b/mp4.c index deb05747..d8aea783 100644 --- a/mp4.c +++ b/mp4.c @@ -599,8 +599,6 @@ static int32_t read_stsd(struct mp4 *f) static int32_t tag_add_field(struct mp4_metadata *tags, const char *item, const char *value, int32_t len) { - if (!item || (item && !*item) || !value) - return 0; tags->tags = para_realloc(tags->tags, (tags->count + 1) * sizeof(struct mp4_tag)); tags->tags[tags->count].item = para_strdup(item); @@ -673,7 +671,6 @@ static const char *get_metadata_name(uint8_t atom_type) static void parse_tag(struct mp4 *f, uint8_t parent, int32_t size) { uint64_t subsize, sumsize; - char *name = NULL; char *data = NULL; uint32_t len = 0; uint64_t destpos; @@ -687,13 +684,6 @@ static void parse_tag(struct mp4 *f, uint8_t parent, int32_t size) uint8_t header_size = 0; subsize = atom_read_header(f, &atom_type, &header_size); destpos = get_position(f) + subsize - header_size; - if (atom_type == ATOM_NAME) { - read_char(f); /* version */ - read_int24(f); /* flags */ - free(name); - name = read_string(f, subsize - (header_size + 4)); - continue; - } if (atom_type != ATOM_DATA) continue; read_char(f); /* version */ @@ -703,13 +693,10 @@ static void parse_tag(struct mp4 *f, uint8_t parent, int32_t size) data = read_string(f, subsize - (header_size + 8)); len = subsize - (header_size + 8); } - if (data) { - if (!name) - name = para_strdup(get_metadata_name(parent)); - tag_add_field(&(f->tags), name, data, len); - free(data); - } - free(name); + if (!data) + return; + tag_add_field(&f->tags, get_metadata_name(parent), data, len); + free(data); } static int32_t read_mdhd(struct mp4 *f) -- 2.39.2