From f76d886f794c80a3c761613532d6a9a72a918cb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 30 Aug 2015 17:43:45 -0400 Subject: [PATCH] Fix: UTF-8 characters may be stored on up to 4 bytes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/common/config/config.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/config/config.c b/src/common/config/config.c index 03601be48..140f3b6dc 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -340,11 +340,10 @@ static xmlChar *encode_string(const char *in_str) in_len = strlen(in_str); /* - * Add 1 byte for the NULL terminted character. The factor 2 here is - * because UTF-8 can be on two bytes so this fits the worst case for each - * bytes. + * Add 1 byte for the NULL terminted character. The factor 4 here is + * used because UTF-8 characters can take up to 4 bytes. */ - out_len = (in_len * 2) + 1; + out_len = (in_len * 4) + 1; out_str = xmlMalloc(out_len); if (!out_str) { goto end; -- 2.34.1