unistr/u8-mbtouc: Improve handling of ill-formed UTF-8 input.
[gnulib.git] / lib / unistr / u8-mbsnlen.c
index 9ddc42e..f72c91c 100644 (file)
@@ -33,7 +33,9 @@ u8_mbsnlen (const uint8_t *s, size_t n)
       characters++;
       if (count == -2)
         break;
-      if (count <= 0)
+      if (count < 0)
+        count = u8_mbtouc (&uc, s, n);
+      else if (count == 0)
         count = 1;
       s += count;
       n -= count;