vlc | branch: master | Francois Cartegnie <fcvlc...@free.fr> | Mon Apr 23 17:23:01 2018 +0200| [7ac4815eb48e2d8060da136ef831ab036d0a1b11] | committer: Francois Cartegnie
codec: subsdec: avoid double copy > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7ac4815eb48e2d8060da136ef831ab036d0a1b11 --- modules/codec/subsdec.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/codec/subsdec.c b/modules/codec/subsdec.c index 5a63f0b2f2..9b6f5c57cd 100644 --- a/modules/codec/subsdec.c +++ b/modules/codec/subsdec.c @@ -381,12 +381,18 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block ) return NULL; } + char *psz_subtitle = NULL; + /* Should be resiliant against bad subtitles */ - char *psz_subtitle = malloc( p_block->i_buffer + 1 ); - if( psz_subtitle == NULL ) - return NULL; - memcpy( psz_subtitle, p_block->p_buffer, p_block->i_buffer ); - psz_subtitle[p_block->i_buffer] = '\0'; + if( p_sys->iconv_handle == (vlc_iconv_t)-1 || + p_sys->b_autodetect_utf8 ) + { + psz_subtitle = malloc( p_block->i_buffer + 1 ); + if( psz_subtitle == NULL ) + return NULL; + memcpy( psz_subtitle, p_block->p_buffer, p_block->i_buffer ); + psz_subtitle[p_block->i_buffer] = '\0'; + } if( p_sys->iconv_handle == (vlc_iconv_t)-1 ) { @@ -415,7 +421,8 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block ) size_t outbytes_left = 6 * inbytes_left; char *psz_new_subtitle = xmalloc( outbytes_left + 1 ); char *psz_convert_buffer_out = psz_new_subtitle; - const char *psz_convert_buffer_in = psz_subtitle; + const char *psz_convert_buffer_in = + psz_subtitle ? psz_subtitle : (char *)p_block->p_buffer; size_t ret = vlc_iconv( p_sys->iconv_handle, &psz_convert_buffer_in, &inbytes_left, _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits