From 05ffeb76c9640ff36722d8f4e9787e3ef1b187d3 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 10 Aug 2021 19:08:41 +0200 Subject: [PATCH] mp4: Prefer para_realloc() over plain realloc(). This allows us to skip the NULL check, which simplifies the code a bit. --- mp4.c | 47 ++++++++++++----------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/mp4.c b/mp4.c index 40d8bd1b..548f78ec 100644 --- a/mp4.c +++ b/mp4.c @@ -763,29 +763,22 @@ static int32_t read_mvhd(struct mp4ff *f) static int32_t tag_add_field(struct mp4ff_metadata *tags, const char *item, const char *value, int32_t len) { - void *backup = (void *) tags->tags; - if (!item || (item && !*item) || !value) return 0; - tags->tags = (struct mp4ff_tag *)realloc(tags->tags, + tags->tags = para_realloc(tags->tags, (tags->count + 1) * sizeof(struct mp4ff_tag)); - if (!tags->tags) { - free(backup); - return 0; + tags->tags[tags->count].item = para_strdup(item); + tags->tags[tags->count].len = len; + if (len >= 0) { + tags->tags[tags->count].value = para_malloc(len + 1); + memcpy(tags->tags[tags->count].value, value, len); + tags->tags[tags->count].value[len] = 0; } else { - tags->tags[tags->count].item = para_strdup(item); - tags->tags[tags->count].len = len; - if (len >= 0) { - tags->tags[tags->count].value = para_malloc(len + 1); - memcpy(tags->tags[tags->count].value, value, len); - tags->tags[tags->count].value[len] = 0; - } else { - tags->tags[tags->count].value = para_strdup(value); - } - tags->count++; - return 1; + tags->tags[tags->count].value = para_strdup(value); } + tags->count++; + return 1; } static const char *ID3v1GenreList[] = { @@ -1581,17 +1574,7 @@ static unsigned membuffer_write(struct membuffer *buf, const void *ptr, unsigned do { buf->allocated <<= 1; } while (dest_size > buf->allocated); - - { - void *newptr = realloc(buf->data, buf->allocated); - if (newptr == 0) { - free(buf->data); - buf->data = 0; - buf->error = 1; - return 0; - } - buf->data = newptr; - } + buf->data = para_realloc(buf->data, buf->allocated); } if (ptr) @@ -1769,15 +1752,9 @@ static void *membuffer_detach(struct membuffer *buf) if (buf->error) return 0; - - ret = realloc(buf->data, buf->written); - - if (ret == 0) - free(buf->data); - + ret = para_realloc(buf->data, buf->written); buf->data = 0; buf->error = 1; - return ret; } -- 2.39.2