From dc1f0f09c653737491efda0e20f6f0bacb45da10 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Sun, 16 Jan 2011 13:53:18 -0200 Subject: [PATCH] Stop UTF-8 to wchar conversion at end of string This save us unnecessary conversions and attempts to convert unitialized values, as reported by Valgrind. Signed-off-by: Claudio Matsuoka --- utf8.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utf8.c b/utf8.c index b4d12af..b8338c1 100644 --- a/utf8.c +++ b/utf8.c @@ -174,6 +174,9 @@ utf8_to_wchar(const char *in, size_t insize, wchar_t *out, size_t outsize, } *out |= high << n_bits; + if (*out == 0) /* return at end of string */ + break; + if (__wchar_forbitten(*out) != 0) { if ((flags & UTF8_IGNORE_ERROR) == 0) return (0); /* forbitten character */