Commit b54422a8 authored by Henrik Gramner's avatar Henrik Gramner Committed by Fiona Glaser

Use calloc instead of malloc + memset

parent 8b58a4ce
...@@ -75,11 +75,10 @@ static int write_header( flv_buffer *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 ) 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; *p_handle = NULL;
flv_hnd_t *p_flv = calloc( 1, sizeof(flv_hnd_t) );
if( !p_flv ) if( !p_flv )
return -1; return -1;
memset( p_flv, 0, sizeof(*p_flv) );
p_flv->b_dts_compress = opt->use_dts_compress; p_flv->b_dts_compress = opt->use_dts_compress;
......
...@@ -87,11 +87,9 @@ void flv_put_amf_double( flv_buffer *c, double d ) ...@@ -87,11 +87,9 @@ void flv_put_amf_double( flv_buffer *c, double d )
flv_buffer *flv_create_writer( const char *filename ) flv_buffer *flv_create_writer( const char *filename )
{ {
flv_buffer *c = malloc( sizeof(*c) ); flv_buffer *c = calloc( 1, sizeof(flv_buffer) );
if( !c ) if( !c )
return NULL; return NULL;
memset( c, 0, sizeof(*c) );
if( !strcmp( filename, "-" ) ) if( !strcmp( filename, "-" ) )
c->fp = stdout; c->fp = stdout;
......
...@@ -44,16 +44,11 @@ typedef struct ...@@ -44,16 +44,11 @@ typedef struct
static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ) 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_handle = NULL;
mkv_hnd_t *p_mkv = calloc( 1, sizeof(mkv_hnd_t) );
p_mkv = malloc( sizeof(*p_mkv) );
if( !p_mkv ) if( !p_mkv )
return -1; return -1;
memset( p_mkv, 0, sizeof(*p_mkv) );
p_mkv->w = mk_create_writer( psz_filename ); p_mkv->w = mk_create_writer( psz_filename );
if( !p_mkv->w ) if( !p_mkv->w )
{ {
......
...@@ -74,10 +74,9 @@ static mk_context *mk_create_context( mk_writer *w, mk_context *parent, unsigned ...@@ -74,10 +74,9 @@ static mk_context *mk_create_context( mk_writer *w, mk_context *parent, unsigned
} }
else else
{ {
c = malloc( sizeof(*c) ); c = calloc( 1, sizeof(mk_context) );
if( !c ) if( !c )
return NULL; return NULL;
memset( c, 0, sizeof(*c) );
} }
c->parent = parent; c->parent = parent;
...@@ -291,12 +290,10 @@ static int mk_write_float( mk_context *c, unsigned id, float f ) ...@@ -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 *mk_create_writer( const char *filename )
{ {
mk_writer *w = malloc( sizeof(*w) ); mk_writer *w = calloc( 1, sizeof(mk_writer) );
if( !w ) if( !w )
return NULL; return NULL;
memset( w, 0, sizeof(*w) );
w->root = mk_create_context( w, NULL, 0 ); w->root = mk_create_context( w, NULL, 0 );
if( !w->root ) if( !w->root )
{ {
......
...@@ -165,8 +165,6 @@ static int close_file( hnd_t handle, int64_t largest_pts, int64_t second_largest ...@@ -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 ) static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt )
{ {
mp4_hnd_t *p_mp4;
*p_handle = NULL; *p_handle = NULL;
FILE *fh = x264_fopen( psz_filename, "w" ); FILE *fh = x264_fopen( psz_filename, "w" );
if( !fh ) if( !fh )
...@@ -174,11 +172,10 @@ static int open_file( char *psz_filename, hnd_t *p_handle, cli_output_opt_t *opt ...@@ -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 ) FAIL_IF_ERR( !x264_is_regular_file( fh ), "mp4", "MP4 output is incompatible with non-regular file `%s'\n", psz_filename )
fclose( fh ); 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; return -1;
memset( p_mp4, 0, sizeof(mp4_hnd_t) );
#ifdef _WIN32 #ifdef _WIN32
/* GPAC doesn't support Unicode filenames. */ /* GPAC doesn't support Unicode filenames. */
char ansi_filename[MAX_PATH]; char ansi_filename[MAX_PATH];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment