[vlc-devel] commit: Use asprintf and check for the return value. ( better than malloc+sprintf) ( Rémi Duraffort )
git version control
git at videolan.org
Wed Oct 29 21:42:52 CET 2008
vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Wed Oct 29 19:39:22 2008 +0100| [5d085ee8fce3e56a3d590532a744ac203a219256] | committer: Rémi Duraffort
Use asprintf and check for the return value. (better than malloc+sprintf)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5d085ee8fce3e56a3d590532a744ac203a219256
---
src/libvlc.c | 4 +---
src/misc/variables.c | 6 +++---
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/libvlc.c b/src/libvlc.c
index dc757fc..f085509 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -883,10 +883,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
*psz_parser = '\0';
psz_parser++;
}
- psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
- if( psz_temp )
+ if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
{
- sprintf( psz_temp, "%s,none", psz_module );
libvlc_InternalAddIntf( p_libvlc, psz_temp );
free( psz_temp );
}
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 5e4e7df..1512ea6 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -1577,9 +1577,9 @@ int __var_Command( vlc_object_t *p_this, const char *psz_name,
if( psz_msg )
{
- *psz_msg = (char*)malloc( 80 );
- sprintf( *psz_msg, "%s on object %s returned %i (%s)",
- psz_cmd, psz_name, i_ret, vlc_error( i_ret ) );
+ if( asprintf( psz_msg, "%s on object %s returned %i (%s)",
+ psz_cmd, psz_name, i_ret, vlc_error( i_ret ) ) == -1)
+ *psz_msg = NULL;
}
return i_ret;
More information about the vlc-devel
mailing list