[vlc-devel] [PATCH] input: Allocate an enough buffer for UTF-8

KO Myung-Hun komh78 at gmail.com
Fri Oct 12 18:09:21 CEST 2012


---
 src/input/stream.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/input/stream.c b/src/input/stream.c
index 67c0297..bb8c1ca 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -1597,16 +1597,20 @@ char *stream_ReadLine( stream_t *s )
         i_line += s->p_text->i_char_width; /* the added \0 */
         if( s->p_text->i_char_width > 1 )
         {
+            int i_new_line = 0;
             size_t i_in = 0, i_out = 0;
             const char * p_in = NULL;
             char * p_out = NULL;
             char * psz_new_line = NULL;
 
             /* iconv */
-            psz_new_line = malloc( i_line );
+            /* UTF-8 needs at most twice the buffer as many as UTF-16 */
+            i_new_line = i_line * 2;
+            psz_new_line = malloc( i_new_line );
             if( psz_new_line == NULL )
                 goto error;
-            i_in = i_out = (size_t)i_line;
+            i_in = (size_t)i_line;
+            i_out = (size_t)i_new_line;
             p_in = p_line;
             p_out = psz_new_line;
 
@@ -1617,7 +1621,7 @@ char *stream_ReadLine( stream_t *s )
             }
             free( p_line );
             p_line = psz_new_line;
-            i_line = (size_t)i_line - i_out; /* does not include \0 */
+            i_line = (size_t)i_new_line - i_out; /* does not include \0 */
         }
 
         /* Remove trailing LF/CR */
-- 
1.7.3.2




More information about the vlc-devel mailing list