]> granicus.if.org Git - libexpat/commitdiff
Extract function align_limit_to_full_utf8_characters
authorSebastian Pipping <sebastian@pipping.org>
Fri, 20 May 2016 18:33:39 +0000 (20:33 +0200)
committerSebastian Pipping <sebastian@pipping.org>
Fri, 20 May 2016 20:11:56 +0000 (22:11 +0200)
expat/lib/xmltok.c

index 0e68844eb512265f26395cfe7509f25f97cc09f5..62b75ae651694c3550268ba7b20d8379b73cb6ed 100644 (file)
@@ -329,6 +329,16 @@ enum {  /* UTF8_cvalN is value of masked first byte of N byte sequence */
   UTF8_cval4 = 0xf0
 };
 
+static void
+align_limit_to_full_utf8_characters(const char * from, const char ** fromLimRef)
+{
+  const char * fromLim = *fromLimRef;
+  for (; fromLim > from; fromLim--)
+    if (((unsigned char)fromLim[-1] & 0xc0) != 0x80)
+      break;
+  *fromLimRef = fromLim;
+}
+
 static enum XML_Convert_Result PTRCALL
 utf8_toUtf8(const ENCODING *UNUSED_P(enc),
             const char **fromP, const char *fromLim,
@@ -340,9 +350,8 @@ utf8_toUtf8(const ENCODING *UNUSED_P(enc),
   if (fromLim - *fromP > toLim - *toP) {
     /* Avoid copying partial characters. */
     res = XML_CONVERT_OUTPUT_EXHAUSTED;
-    for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--)
-      if (((unsigned char)fromLim[-1] & 0xc0) != 0x80)
-        break;
+    fromLim = *fromP + (toLim - *toP);
+    align_limit_to_full_utf8_characters(*fromP, &fromLim);
   }
   for (to = *toP, from = *fromP; (from < fromLim) && (to < toLim); from++, to++)
     *to = *from;