diff apetag.c @ 5446:4211f91f69b1 libavformat

Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped arrays of fixed length. Code from ffmbc with changes to adapt to our metadata API.
author michael
date Sun, 13 Dec 2009 20:27:29 +0000
parents 08c073da6553
children ab9e31e90d3c
line wrap: on
line diff
--- a/apetag.c	Sun Dec 13 20:22:27 2009 +0000
+++ b/apetag.c	Sun Dec 13 20:27:29 2009 +0000
@@ -33,7 +33,7 @@
 static int ape_tag_read_field(AVFormatContext *s)
 {
     ByteIOContext *pb = s->pb;
-    uint8_t key[1024], value[1024];
+    uint8_t key[1024], *value;
     uint32_t size, flags;
     int i, l, c;
 
@@ -51,13 +51,14 @@
         av_log(s, AV_LOG_WARNING, "Invalid APE tag key '%s'.\n", key);
         return -1;
     }
-    l = FFMIN(size, sizeof(value)-1);
-    get_buffer(pb, value, l);
-    value[l] = 0;
-    url_fskip(pb, size-l);
-    if (l < size)
-        av_log(s, AV_LOG_WARNING, "Too long '%s' tag was truncated.\n", key);
-    av_metadata_set(&s->metadata, key, value);
+    if (size >= UINT_MAX)
+        return -1;
+    value = av_malloc(size+1);
+    if (!value)
+        return AVERROR_NOMEM;
+    get_buffer(pb, value, size);
+    value[size] = 0;
+    av_metadata_set2(&s->metadata, key, value, AV_METADATA_DONT_STRDUP_VAL);
     return 0;
 }