[vlc-devel] commit: Use vasprintf instead of some malloc+vsnprintf and fix CID 194. ( Rémi Duraffort )

git version control git at videolan.org
Sun Oct 5 15:38:21 CEST 2008


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Sun Oct  5 15:10:24 2008 +0200| [f2143d069645d2a79e7068621b8acc2a97d4fe74] | committer: Rémi Duraffort 

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

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f2143d069645d2a79e7068621b8acc2a97d4fe74
---

 .../dynamicoverlay/dynamicoverlay_buffer.c         |   22 +++++--------------
 1 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/modules/video_filter/dynamicoverlay/dynamicoverlay_buffer.c b/modules/video_filter/dynamicoverlay/dynamicoverlay_buffer.c
index e24518a..dce831b 100644
--- a/modules/video_filter/dynamicoverlay/dynamicoverlay_buffer.c
+++ b/modules/video_filter/dynamicoverlay/dynamicoverlay_buffer.c
@@ -121,24 +121,14 @@ int BufferPrintf( buffer_t *p_buffer, const char *p_fmt, ... )
     int status;
     char *psz_data;
 
-    va_list va_list1, va_list2;
-    va_start( va_list1, p_fmt );
-    va_copy( va_list2, va_list1 );
+    va_list va;
+    va_start( va, p_fmt );
 
-    i_len = vsnprintf( NULL, 0, p_fmt, va_list1 );
-    if( i_len < 0 )
-        return VLC_EGENERIC;
-    va_end( va_list1 );
-
-    psz_data = malloc( i_len + 1 );
-    if( psz_data == NULL ) {
+    i_len = vasprintf( &psz_data, p_fmt, va );
+    va_end( va );
+    if( i_len == -1 )
         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 );
     free( psz_data );
     return status;




More information about the vlc-devel mailing list