From: Henrik Gramner Date: Fri, 18 Oct 2013 20:21:38 +0000 (+0200) Subject: Use calloc instead of malloc + memset X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b54422a858809f39c00fac46207bfa8ad16cdb28;p=libx264 Use calloc instead of malloc + memset --- diff --git a/output/flv.c b/output/flv.c index 6f972f74..46e46b36 100644 --- a/output/flv.c +++ b/output/flv.c @@ -75,11 +75,10 @@ static int write_header( flv_buffer *c ) static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ) { - flv_hnd_t *p_flv = malloc( sizeof(*p_flv) ); *p_handle = NULL; + flv_hnd_t *p_flv = calloc( 1, sizeof(flv_hnd_t) ); if( !p_flv ) return -1; - memset( p_flv, 0, sizeof(*p_flv) ); p_flv->b_dts_compress = opt->use_dts_compress; diff --git a/output/flv_bytestream.c b/output/flv_bytestream.c index 38a4ca9e..b6c29a2a 100644 --- a/output/flv_bytestream.c +++ b/output/flv_bytestream.c @@ -87,11 +87,9 @@ void flv_put_amf_double( flv_buffer *c, double d ) flv_buffer *flv_create_writer( const char *filename ) { - flv_buffer *c = malloc( sizeof(*c) ); - + flv_buffer *c = calloc( 1, sizeof(flv_buffer) ); if( !c ) return NULL; - memset( c, 0, sizeof(*c) ); if( !strcmp( filename, "-" ) ) c->fp = stdout; diff --git a/output/matroska.c b/output/matroska.c index 9b832845..00a13f56 100644 --- a/output/matroska.c +++ b/output/matroska.c @@ -44,16 +44,11 @@ typedef struct static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ) { - mkv_hnd_t *p_mkv; - *p_handle = NULL; - - p_mkv = malloc( sizeof(*p_mkv) ); + mkv_hnd_t *p_mkv = calloc( 1, sizeof(mkv_hnd_t) ); if( !p_mkv ) return -1; - memset( p_mkv, 0, sizeof(*p_mkv) ); - p_mkv->w = mk_create_writer( psz_filename ); if( !p_mkv->w ) { diff --git a/output/matroska_ebml.c b/output/matroska_ebml.c index 12c43d55..943c65ee 100644 --- a/output/matroska_ebml.c +++ b/output/matroska_ebml.c @@ -74,10 +74,9 @@ static mk_context *mk_create_context( mk_writer *w, mk_context *parent, unsigned } else { - c = malloc( sizeof(*c) ); + c = calloc( 1, sizeof(mk_context) ); if( !c ) return NULL; - memset( c, 0, sizeof(*c) ); } c->parent = parent; @@ -291,12 +290,10 @@ static int mk_write_float( mk_context *c, unsigned id, float f ) mk_writer *mk_create_writer( const char *filename ) { - mk_writer *w = malloc( sizeof(*w) ); + mk_writer *w = calloc( 1, sizeof(mk_writer) ); if( !w ) return NULL; - memset( w, 0, sizeof(*w) ); - w->root = mk_create_context( w, NULL, 0 ); if( !w->root ) { diff --git a/output/mp4.c b/output/mp4.c index f5471b91..8093b2b7 100644 --- a/output/mp4.c +++ b/output/mp4.c @@ -165,8 +165,6 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ) { - mp4_hnd_t *p_mp4; - *p_handle = NULL; FILE *fh = x264_fopen( psz_filename, "w" ); if( !fh ) @@ -174,11 +172,10 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt FAIL_IF_ERR( !x264_is_regular_file( fh ), "mp4", "MP4 output is incompatible with non-regular file `%s'\n", psz_filename ) fclose( fh ); - if( !(p_mp4 = malloc( sizeof(mp4_hnd_t) )) ) + mp4_hnd_t *p_mp4 = calloc( 1, sizeof(mp4_hnd_t) ); + if( !p_mp4 ) return -1; - memset( p_mp4, 0, sizeof(mp4_hnd_t) ); - #ifdef _WIN32 /* GPAC doesn't support Unicode filenames. */ char ansi_filename[MAX_PATH];