]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Use para_strdup().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 9 Aug 2021 18:05:10 +0000 (20:05 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
Like malloc(), strdup() may fail. The current code does not always
check that. Using the paraslash wrapper avoids the issue and has the
additional benefit that para_strdup(NULL) does not segfault.

mp4.c

diff --git a/mp4.c b/mp4.c
index 9b09a8f407822f6baee40a0440b729fb7a35787d..8f1ddec2d842d1531428ab75b0c5027c3da65492 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -773,25 +773,15 @@ static int32_t mp4ff_tag_add_field(mp4ff_metadata_t * tags, const char *item,
                free(backup);
                return 0;
        } else {
-               tags->tags[tags->count].item = strdup(item);
+               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 = strdup(value);
+                       tags->tags[tags->count].value = para_strdup(value);
                }
-
-               if (!tags->tags[tags->count].item || !tags->tags[tags->count].value) {
-                       free(tags->tags[tags->count].item);
-                       free(tags->tags[tags->count].value);
-                       tags->tags[tags->count].item = NULL;
-                       tags->tags[tags->count].value = NULL;
-                       tags->tags[tags->count].len = 0;
-                       return 0;
-               }
-
                tags->count++;
                return 1;
        }
@@ -958,8 +948,7 @@ static int32_t mp4ff_set_metadata_name(const uint8_t atom_type, char **name)
                break;
        }
 
-       *name = strdup(tag_names[tag_idx]);
-
+       *name = para_strdup(tag_names[tag_idx]);
        return 0;
 }
 
@@ -1475,8 +1464,8 @@ int32_t mp4ff_meta_get_by_index(const mp4ff_t * f, uint32_t index,
                *value = NULL;
                return 0;
        } else {
-               *item = strdup(f->tags.tags[index].item);
-               *value = strdup(f->tags.tags[index].value);
+               *item = para_strdup(f->tags.tags[index].item);
+               *value = para_strdup(f->tags.tags[index].value);
                return 1;
        }
 }
@@ -2165,7 +2154,7 @@ static int32_t mp4ff_meta_find_by_name(const mp4ff_t * f, const char *item,
 
        for (i = 0; i < f->tags.count; i++) {
                if (!stricmp(f->tags.tags[i].item, item)) {
-                       *value = strdup(f->tags.tags[i].value);
+                       *value = para_strdup(f->tags.tags[i].value);
                        return 1;
                }
        }