matroskadec: use av_grow_packet in merge_packets.
authorNicolas George <nicolas.george@normalesup.org>
Mon, 16 Apr 2012 16:02:02 +0000 (18:02 +0200)
committerNicolas George <nicolas.george@normalesup.org>
Mon, 16 Apr 2012 20:17:24 +0000 (22:17 +0200)
It ensures that the packet is properly padded
and makes the code simpler.

Fixes trac ticket #1223.

libavformat/matroskadec.c

index 27d84ad..a484c50 100644 (file)
@@ -1126,12 +1126,10 @@ static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska,
 
 static int matroska_merge_packets(AVPacket *out, AVPacket *in)
 {
-    void *newdata = av_realloc(out->data, out->size+in->size);
-    if (!newdata)
-        return AVERROR(ENOMEM);
-    out->data = newdata;
-    memcpy(out->data+out->size, in->data, in->size);
-    out->size += in->size;
+    int ret = av_grow_packet(out, in->size);
+    if (ret < 0)
+        return ret;
+    memcpy(out->data + out->size - in->size, in->data, in->size);
     av_destruct_packet(in);
     av_free(in);
     return 0;