[vlc-devel] [PATCH] input: Allocate an enough buffer for UTF-8
Rémi Denis-Courmont
remi at remlab.net
Fri Oct 12 18:43:57 CEST 2012
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>
--
Rémi Denis-Courmont
http://www.remlab.net/
More information about the vlc-devel
mailing list