]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Prefer para_realloc() over plain realloc().
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 10 Aug 2021 17:08:41 +0000 (19:08 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
This allows us to skip the NULL check, which simplifies the code a bit.

mp4.c

diff --git a/mp4.c b/mp4.c
index 40d8bd1bb79d5e5d2806fd4c771bd9e13bc0ac1f..548f78ec391e95f892fdba61cf2140db25a473d0 100644 (file)
--- 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;
 }