Fix mbsrtowcs(3) src param for finished string.

A mistake I made while cleaning this up the first time through.
mbstrtowcs(3) sets the src param to null if it finishes the string.

Change-Id: I6263646e25d9537043b7025fd1dd6ae195f365e2
(cherry picked from commit b6cc8e00cd)
This commit is contained in:
Dan Albert 2014-07-31 11:31:03 -07:00
parent 00a8344ae8
commit 938a8008a6
2 changed files with 5 additions and 2 deletions

View File

@ -84,6 +84,7 @@ size_t mbsnrtowcs(wchar_t* dst, const char** src, size_t nmc, size_t len, mbstat
if (static_cast<uint8_t>((*src)[i]) < 0x80) {
// Fast path for plain ASCII characters.
if ((*src)[i] == '\0') {
*src = nullptr;
return reset_and_return(o, state);
}
r = 1;
@ -96,6 +97,7 @@ size_t mbsnrtowcs(wchar_t* dst, const char** src, size_t nmc, size_t len, mbstat
return reset_and_return_illegal(EILSEQ, state);
}
if (r == 0) {
*src = nullptr;
return reset_and_return(o, state);
}
}
@ -118,7 +120,8 @@ size_t mbsnrtowcs(wchar_t* dst, const char** src, size_t nmc, size_t len, mbstat
dst[o] = (*src)[i];
r = 1;
if ((*src)[i] == '\0') {
break;
*src = nullptr;
return reset_and_return(o, state);
}
} else {
r = mbrtowc(dst + o, *src + i, nmc - i, state);

View File

@ -351,7 +351,7 @@ void test_mbsrtowcs(mbstate_t* ps) {
// Check that we didn't clobber the rest of out.
ASSERT_EQ(L'x', out[3]);
// Check that valid has advanced to the end of the string.
ASSERT_EQ(L'\0', *valid);
ASSERT_EQ(nullptr, valid);
const char* invalid = "A" "\xc2\x20" "ef";
ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(out, &invalid, 4, ps));