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

KO Myung-Hun git at videolan.org
Sat Oct 13 09:15:51 CEST 2012


vlc | branch: master | KO Myung-Hun <komh78 at gmail.com> | Sat Oct 13 10:39:27 2012 +0900| [f929e866e18a94b1c61b4747e56bcd2d2d818551] | committer: Rémi Denis-Courmont

input: Allocate an enough buffer for UTF-8

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

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

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

diff --git a/src/input/stream.c b/src/input/stream.c
index 67c0297..189f281 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 150% of the buffer as many as UTF-16 */
+            i_new_line = i_line * 3 / 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 */



More information about the vlc-commits mailing list