Fix mbsrtowcs(3)'s handling of len parameter.
The len parameter is a _maximum_ length. The previous code was treating
it as an exact length, causing the following typical call to fail:
mbsrtowcs(out, &in, sizeof(out), state); // sizeof(out) > strlen(in)
Change-Id: I48e474fd54ea5f122bc168a4d74bfe08704f28cc
diff --git a/libc/bionic/wchar.cpp b/libc/bionic/wchar.cpp
index ecb8b33..438ce03 100644
--- a/libc/bionic/wchar.cpp
+++ b/libc/bionic/wchar.cpp
@@ -116,11 +116,10 @@
if (static_cast<uint8_t>((*src)[i]) < 0x80) {
// Fast path for plain ASCII characters.
dst[o] = (*src)[i];
- if ((*src)[i] == '\0') {
- *src = NULL;
- return reset_and_return_illegal(EILSEQ, state);
- }
r = 1;
+ if ((*src)[i] == '\0') {
+ break;
+ }
} else {
r = mbrtowc(dst + o, *src + i, nmc - i, state);
if (r == __MB_ERR_ILLEGAL_SEQUENCE) {