Commit f2143d06 authored by Rémi Duraffort's avatar Rémi Duraffort

Use vasprintf instead of some malloc+vsnprintf and fix CID 194.

parent e30ee3d5
...@@ -121,24 +121,14 @@ int BufferPrintf( buffer_t *p_buffer, const char *p_fmt, ... ) ...@@ -121,24 +121,14 @@ int BufferPrintf( buffer_t *p_buffer, const char *p_fmt, ... )
int status; int status;
char *psz_data; char *psz_data;
va_list va_list1, va_list2; va_list va;
va_start( va_list1, p_fmt ); va_start( va, p_fmt );
va_copy( va_list2, va_list1 );
i_len = vsnprintf( NULL, 0, p_fmt, va_list1 ); i_len = vasprintf( &psz_data, p_fmt, va );
if( i_len < 0 ) va_end( va );
return VLC_EGENERIC; if( i_len == -1 )
va_end( va_list1 );
psz_data = malloc( i_len + 1 );
if( psz_data == NULL ) {
return VLC_ENOMEM; return VLC_ENOMEM;
}
if( vsnprintf( psz_data, i_len + 1, p_fmt, va_list2 ) != i_len )
{
return VLC_EGENERIC;
}
va_end( va_list2 );
status = BufferAdd( p_buffer, psz_data, i_len ); status = BufferAdd( p_buffer, psz_data, i_len );
free( psz_data ); free( psz_data );
return status; return status;
......
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