[vlc-commits] codec: subsdec: avoid double copy

Francois Cartegnie git at videolan.org
Tue Apr 24 13:17:30 CEST 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Apr 23 17:23:01 2018 +0200| [7c1d21a59711864e72da17214a7540f93ef56d75] | committer: Thomas Guillem

codec: subsdec: avoid double copy

(cherry picked from commit 7ac4815eb48e2d8060da136ef831ab036d0a1b11)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 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,



More information about the vlc-commits mailing list