>From c0218ca4bb6ef6518fe5e8b4335df665085d4ecd Mon Sep 17 00:00:00 2001
From: KO Myung-Hun <komh@chollian.net>
Date: Sat, 13 Oct 2012 00:31:53 +0900
Subject: [PATCH] input: Allocate an enough buffer for UTF-8

---
 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..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 */
-- 
1.7.3.2

