[vlc-commits] packetizer: mpeg4video: remove xrealloc and unconditional memcpy

Francois Cartegnie git at videolan.org
Wed Jan 13 16:57:13 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jan 13 13:17:28 2021 +0100| [76e49f95c94dc4488fdf0f304805d30959c2b574] | committer: Francois Cartegnie

packetizer: mpeg4video: remove xrealloc and unconditional memcpy

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=76e49f95c94dc4488fdf0f304805d30959c2b574
---

 modules/packetizer/mpeg4video.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/modules/packetizer/mpeg4video.c b/modules/packetizer/mpeg4video.c
index f2709f1206..85ad7e9165 100644
--- a/modules/packetizer/mpeg4video.c
+++ b/modules/packetizer/mpeg4video.c
@@ -293,13 +293,18 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
              i_startcode < RESERVED_START_CODE )
     {
         /* Copy the complete VOL */
-        if( (size_t)p_dec->fmt_out.i_extra != p_frag->i_buffer )
+        if( (size_t)p_dec->fmt_out.i_extra != p_frag->i_buffer ||
+           ( p_frag->i_buffer && memcmp(p_dec->fmt_out.p_extra,
+                                        p_frag->p_buffer, p_frag->i_buffer) ) )
         {
-            p_dec->fmt_out.p_extra =
-                xrealloc( p_dec->fmt_out.p_extra, p_frag->i_buffer );
-            p_dec->fmt_out.i_extra = p_frag->i_buffer;
+            void *p_realloc = realloc( p_dec->fmt_out.p_extra, p_frag->i_buffer );
+            if( p_realloc )
+            {
+                p_dec->fmt_out.p_extra = p_realloc;
+                p_dec->fmt_out.i_extra = p_frag->i_buffer;
+                memcpy( p_realloc, p_frag->p_buffer, p_frag->i_buffer );
+            }
         }
-        memcpy( p_dec->fmt_out.p_extra, p_frag->p_buffer, p_frag->i_buffer );
         ParseVOL( p_dec, &p_dec->fmt_out,
                   p_dec->fmt_out.p_extra, p_dec->fmt_out.i_extra );
 



More information about the vlc-commits mailing list