changeset 17597:a3a4f7408f90

add some sanity checks to new/resize_demux_packet
author reimar
date Sun, 12 Feb 2006 09:28:09 +0000
parents 52fb9a8bf702
children 4b8193d51bda
files libmpdemux/demuxer.h
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demuxer.h	Sun Feb 12 08:03:58 2006 +0000
+++ b/libmpdemux/demuxer.h	Sun Feb 12 09:28:09 2006 +0000
@@ -190,17 +190,18 @@
   dp->flags=0;
   dp->refcount=1;
   dp->master=NULL;
-  dp->buffer=len?(unsigned char*)malloc(len+8):NULL;
-  if(len) memset(dp->buffer+len,0,8);
+  if (len > 0 && (dp->buffer = malloc(len + 8)))
+    memset(dp->buffer + len, 0, 8);
+  else
+    dp->len = 0;
   return dp;
 }
 
 inline static void resize_demux_packet(demux_packet_t* dp, int len)
 {
-  if(len)
+  if(len > 0)
   {
      dp->buffer=(unsigned char *)realloc(dp->buffer,len+8);
-     memset(dp->buffer+len,0,8);
   }
   else
   {
@@ -208,6 +209,10 @@
      dp->buffer=NULL;
   }
   dp->len=len;
+  if (dp->buffer)
+     memset(dp->buffer + len, 0, 8);
+  else
+     dp->len = 0;
 }
 
 inline static demux_packet_t* clone_demux_packet(demux_packet_t* pack){