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

KO Myung-Hun komh78 at gmail.com
Sat Oct 13 03:39:27 CEST 2012



Rémi Denis-Courmont wrote:
> Le vendredi 12 octobre 2012 19:09:21, KO Myung-Hun a écrit :
>> ---
>>  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 */
> 
> That's not quite true. UTF-8 occupies at most 150% of the memory that UTF-16 
> would. On the other hand, UTF-16 occupies at most 200% compared to UTF-8.
> 
> <pre>
> 
>  UTF-8  | UTF-16
> --------+--------
> 1 byte  | 2 bytes }
> 2 bytes | 2 bytes } Basic Multilingual Plane
> 3 bytes | 2 bytes }
> --------+--------
> 4 bytes | 4 bytes } all other Unicode planes
> 
> </pre>
> 

Ok. I fixed to 150%.

-- 
KO Myung-Hun

Using Mozilla SeaMonkey 2.7.2
Under OS/2 Warp 4 for Korean with FixPak #15
In VirtualBox v4.1.18 on Intel Core i7-3615QM 2.30GHz with 8GB RAM

Korean OS/2 User Community : http://www.ecomstation.co.kr

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-input-Allocate-an-enough-buffer-for-UTF-8.patch
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20121013/0452f884/attachment.ksh>


More information about the vlc-devel mailing list