From 0dbbf43fdb20f593ddf4fa1ff67288000dd4a7fd Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 29 Mar 2017 19:11:16 +0200 Subject: [PATCH] utf8_toUtf8: Cut off partial characters in case of sufficient space, too (closes #16) Also, report XML_CONVERT_INPUT_INCOMPLETE properly. --- expat/lib/xmltok.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/expat/lib/xmltok.c b/expat/lib/xmltok.c index b014e72c..016cedb6 100644 --- a/expat/lib/xmltok.c +++ b/expat/lib/xmltok.c @@ -369,24 +369,24 @@ utf8_toUtf8(const ENCODING *UNUSED_P(enc), const char **fromP, const char *fromLim, char **toP, const char *toLim) { - enum XML_Convert_Result res = XML_CONVERT_COMPLETED; char *to; const char *from; - if (fromLim - *fromP > toLim - *toP) { - /* Avoid copying partial characters. */ - res = XML_CONVERT_OUTPUT_EXHAUSTED; - fromLim = *fromP + (toLim - *toP); - align_limit_to_full_utf8_characters(*fromP, &fromLim); - } + const char *fromLimInitial = fromLim; + + /* Avoid copying partial characters. */ + align_limit_to_full_utf8_characters(*fromP, &fromLim); + for (to = *toP, from = *fromP; (from < fromLim) && (to < toLim); from++, to++) *to = *from; *fromP = from; *toP = to; - if ((to == toLim) && (from < fromLim)) + if (fromLim < fromLimInitial) + return XML_CONVERT_INPUT_INCOMPLETE; + else if ((to == toLim) && (from < fromLim)) return XML_CONVERT_OUTPUT_EXHAUSTED; else - return res; + return XML_CONVERT_COMPLETED; } static enum XML_Convert_Result PTRCALL -- 2.40.0