[vlc-commits] demux: avi: remove xmalloc
Francois Cartegnie
git at videolan.org
Fri Jul 28 10:00:05 CEST 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul 27 23:05:57 2017 +0200| [912caf40a2a612a5339b41f169720bd013611de3] | committer: Francois Cartegnie
demux: avi: remove xmalloc
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=912caf40a2a612a5339b41f169720bd013611de3
---
modules/demux/avi/libavi.c | 94 +++++++++++++++++++++++++++++-----------------
1 file changed, 60 insertions(+), 34 deletions(-)
diff --git a/modules/demux/avi/libavi.c b/modules/demux/avi/libavi.c
index f46256a768..35cec915f5 100644
--- a/modules/demux/avi/libavi.c
+++ b/modules/demux/avi/libavi.c
@@ -177,8 +177,10 @@ static int AVI_ChunkRead_list( stream_t *s, avi_chunk_t *p_container )
msg_Dbg( (vlc_object_t*)s, "<list \'%4.4s\'>", (char*)&p_container->list.i_type );
for( ; ; )
{
- p_chk = xmalloc( sizeof( avi_chunk_t ) );
- memset( p_chk, 0, sizeof( avi_chunk_t ) );
+ p_chk = calloc( 1, sizeof( avi_chunk_t ) );
+ if( !p_chk )
+ return VLC_EGENERIC;
+
if( !p_container->common.p_first )
{
p_container->common.p_first = p_chk;
@@ -235,8 +237,13 @@ int AVI_ChunkFetchIndexes( stream_t *s, avi_chunk_t *p_riff )
for( ; ; )
{
- p_chk = xmalloc( sizeof( avi_chunk_t ) );
- memset( p_chk, 0, sizeof( avi_chunk_t ) );
+ p_chk = calloc( 1, sizeof( avi_chunk_t ) );
+ if( !p_chk )
+ {
+ i_ret = VLC_EGENERIC;
+ break;
+ }
+
if (unlikely( !p_riff->common.p_first ))
p_riff->common.p_first = p_chk;
else
@@ -402,7 +409,7 @@ static int AVI_ChunkRead_strf( stream_t *s, avi_chunk_t *p_chk )
{
case( AVIFOURCC_auds ):
p_chk->strf.auds.i_cat = AUDIO_ES;
- p_chk->strf.auds.p_wf = xmalloc( __MAX( p_chk->common.i_chunk_size, sizeof( WAVEFORMATEX ) ) );
+ p_chk->strf.auds.p_wf = malloc( __MAX( p_chk->common.i_chunk_size, sizeof( WAVEFORMATEX ) ) );
if ( !p_chk->strf.auds.p_wf )
{
AVI_READCHUNK_EXIT( VLC_ENOMEM );
@@ -455,7 +462,7 @@ static int AVI_ChunkRead_strf( stream_t *s, avi_chunk_t *p_chk )
case( AVIFOURCC_vids ):
p_strh->strh.i_samplesize = 0; /* XXX for ffmpeg avi file */
p_chk->strf.vids.i_cat = VIDEO_ES;
- p_chk->strf.vids.p_bih = xmalloc( __MAX( p_chk->common.i_chunk_size,
+ p_chk->strf.vids.p_bih = malloc( __MAX( p_chk->common.i_chunk_size,
sizeof( *p_chk->strf.vids.p_bih ) ) );
if ( !p_chk->strf.vids.p_bih )
{
@@ -549,9 +556,10 @@ static int AVI_ChunkRead_strd( stream_t *s, avi_chunk_t *p_chk )
}
AVI_READCHUNK_ENTER;
- p_chk->strd.p_data = xmalloc( p_chk->common.i_chunk_size );
- memcpy( p_chk->strd.p_data, p_buff + 8, p_chk->common.i_chunk_size );
- AVI_READCHUNK_EXIT( VLC_SUCCESS );
+ p_chk->strd.p_data = malloc( p_chk->common.i_chunk_size );
+ if( p_chk->strd.p_data )
+ memcpy( p_chk->strd.p_data, p_buff + 8, p_chk->common.i_chunk_size );
+ AVI_READCHUNK_EXIT( p_chk->strd.p_data ? VLC_SUCCESS : VLC_EGENERIC );
}
static void AVI_ChunkFree_strd( avi_chunk_t *p_chk )
@@ -571,7 +579,9 @@ static int AVI_ChunkRead_idx1( stream_t *s, avi_chunk_t *p_chk )
p_chk->idx1.i_entry_max = i_count;
if( i_count > 0 )
{
- p_chk->idx1.entry = xcalloc( i_count, sizeof( idx1_entry_t ) );
+ p_chk->idx1.entry = calloc( i_count, sizeof( idx1_entry_t ) );
+ if( !p_chk->idx1.entry )
+ AVI_READCHUNK_EXIT( VLC_EGENERIC );
for( i_index = 0; i_index < i_count ; i_index++ )
{
@@ -603,6 +613,7 @@ static void AVI_ChunkFree_idx1( avi_chunk_t *p_chk )
static int AVI_ChunkRead_indx( stream_t *s, avi_chunk_t *p_chk )
{
unsigned int i_count, i;
+ int i_ret = VLC_SUCCESS;
int32_t i_dummy;
VLC_UNUSED(i_dummy);
avi_chunk_indx_t *p_indx = (avi_chunk_indx_t*)p_chk;
@@ -626,13 +637,16 @@ static int AVI_ChunkRead_indx( stream_t *s, avi_chunk_t *p_chk )
i_count = __MIN( p_indx->i_entriesinuse, i_read / 8 );
p_indx->i_entriesinuse = i_count;
- p_indx->idx.std = xcalloc( i_count, sizeof( indx_std_entry_t ) );
-
- for( i = 0; i < i_count; i++ )
+ p_indx->idx.std = calloc( i_count, sizeof( indx_std_entry_t ) );
+ if( i_count == 0 || p_indx->idx.std )
{
- AVI_READ4BYTES( p_indx->idx.std[i].i_offset );
- AVI_READ4BYTES( p_indx->idx.std[i].i_size );
+ for( i = 0; i < i_count; i++ )
+ {
+ AVI_READ4BYTES( p_indx->idx.std[i].i_offset );
+ AVI_READ4BYTES( p_indx->idx.std[i].i_size );
+ }
}
+ else i_ret = VLC_EGENERIC;
}
else if( p_indx->i_indextype == AVI_INDEX_OF_CHUNKS && p_indx->i_indexsubtype == AVI_INDEX_2FIELD )
{
@@ -641,13 +655,17 @@ static int AVI_ChunkRead_indx( stream_t *s, avi_chunk_t *p_chk )
i_count = __MIN( p_indx->i_entriesinuse, i_read / 12 );
p_indx->i_entriesinuse = i_count;
- p_indx->idx.field = xcalloc( i_count, sizeof( indx_field_entry_t ) );
- for( i = 0; i < i_count; i++ )
+ p_indx->idx.field = calloc( i_count, sizeof( indx_field_entry_t ) );
+ if( i_count == 0 || p_indx->idx.field )
{
- AVI_READ4BYTES( p_indx->idx.field[i].i_offset );
- AVI_READ4BYTES( p_indx->idx.field[i].i_size );
- AVI_READ4BYTES( p_indx->idx.field[i].i_offsetfield2 );
+ for( i = 0; i < i_count; i++ )
+ {
+ AVI_READ4BYTES( p_indx->idx.field[i].i_offset );
+ AVI_READ4BYTES( p_indx->idx.field[i].i_size );
+ AVI_READ4BYTES( p_indx->idx.field[i].i_offsetfield2 );
+ }
}
+ else i_ret = VLC_EGENERIC;
}
else if( p_indx->i_indextype == AVI_INDEX_OF_INDEXES )
{
@@ -658,14 +676,17 @@ static int AVI_ChunkRead_indx( stream_t *s, avi_chunk_t *p_chk )
i_count = __MIN( p_indx->i_entriesinuse, i_read / 16 );
p_indx->i_entriesinuse = i_count;
- p_indx->idx.super = xcalloc( i_count, sizeof( indx_super_entry_t ) );
-
- for( i = 0; i < i_count; i++ )
+ p_indx->idx.super = calloc( i_count, sizeof( indx_super_entry_t ) );
+ if( i_count == 0 || p_indx->idx.super )
{
- AVI_READ8BYTES( p_indx->idx.super[i].i_offset );
- AVI_READ4BYTES( p_indx->idx.super[i].i_size );
- AVI_READ4BYTES( p_indx->idx.super[i].i_duration );
+ for( i = 0; i < i_count; i++ )
+ {
+ AVI_READ8BYTES( p_indx->idx.super[i].i_offset );
+ AVI_READ4BYTES( p_indx->idx.super[i].i_size );
+ AVI_READ4BYTES( p_indx->idx.super[i].i_duration );
+ }
}
+ else i_ret = VLC_EGENERIC;
}
else
{
@@ -673,9 +694,10 @@ static int AVI_ChunkRead_indx( stream_t *s, avi_chunk_t *p_chk )
}
#ifdef AVI_DEBUG
- msg_Dbg( (vlc_object_t*)s, "indx: type=%d subtype=%d entry=%d", p_indx->i_indextype, p_indx->i_indexsubtype, p_indx->i_entriesinuse );
+ msg_Dbg( (vlc_object_t*)s, "indx: type=%d subtype=%d entry=%d",
+ p_indx->i_indextype, p_indx->i_indexsubtype, p_indx->i_entriesinuse );
#endif
- AVI_READCHUNK_EXIT( VLC_SUCCESS );
+ AVI_READCHUNK_EXIT( i_ret );
}
static void AVI_ChunkFree_indx( avi_chunk_t *p_chk )
{
@@ -808,12 +830,14 @@ static int AVI_ChunkRead_strz( stream_t *s, avi_chunk_t *p_chk )
}
}
p_strz->p_type = strdup( AVI_strz_type[i_index].psz_type );
- p_strz->p_str = xmalloc( p_strz->i_chunk_size + 1);
-
- if( p_strz->i_chunk_size )
+ p_strz->p_str = malloc( p_strz->i_chunk_size + 1 );
+ if( !p_strz->p_type || !p_strz->p_str )
{
- memcpy( p_strz->p_str, p_read, p_strz->i_chunk_size );
+ free( p_strz->p_type );
+ free( p_strz->p_str );
+ AVI_READCHUNK_EXIT( VLC_EGENERIC );
}
+ memcpy( p_strz->p_str, p_read, p_strz->i_chunk_size );
p_strz->p_str[p_strz->i_chunk_size] = 0;
#ifdef AVI_DEBUG
@@ -1084,8 +1108,10 @@ int AVI_ChunkReadRoot( stream_t *s, avi_chunk_t *p_root )
for( ; ; )
{
- p_chk = xmalloc( sizeof( avi_chunk_t ) );
- memset( p_chk, 0, sizeof( avi_chunk_t ) );
+ p_chk = calloc( 1, sizeof( avi_chunk_t ) );
+ if( !p_chk )
+ return VLC_EGENERIC;
+
if( !p_root->common.p_first )
{
p_root->common.p_first = p_chk;
More information about the vlc-commits
mailing list