[vlc-devel] [PATCH 11/20] mkv: removed indirection when initializing std::string

Filip Roséen filip at videolabs.io
Fri Mar 4 17:04:09 CET 2016


There really is no need to allocate memory for a temporary buffer, copy
the data to this buffer, and then use the buffer to initialize a
std::string, before freeing the buffer.

One of the constructors of std::string can handle the above for us.
---
 modules/demux/mkv/chapter_command.cpp | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/modules/demux/mkv/chapter_command.cpp b/modules/demux/mkv/chapter_command.cpp
index da32529..93403a9 100644
--- a/modules/demux/mkv/chapter_command.cpp
+++ b/modules/demux/mkv/chapter_command.cpp
@@ -706,12 +706,7 @@ bool matroska_script_interpretor_c::Interpret( const binary * p_command, size_t
 {
     bool b_result = false;
 
-    char *psz_str = static_cast<char*>( malloc( i_size + 1 ) );
-    memcpy( psz_str, p_command, i_size );
-    psz_str[ i_size ] = '\0';
-
-    std::string sz_command = psz_str;
-    free( psz_str );
+    std::string sz_command( reinterpret_cast<const char*> (p_command), i_size );
 
     msg_Dbg( &sys.demuxer, "command : %s", sz_command.c_str() );
 
-- 
2.7.2



More information about the vlc-devel mailing list