diff options
author | Dan Albert <danalbert@google.com> | 2014-08-06 21:09:35 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-06 17:19:40 +0000 |
commit | 5b39a44575e01ecf65397ffb7518efc3c65a6d8b (patch) | |
tree | 818df667cf6faefec826a9b6f53e04e33d35e331 | |
parent | 40079b003168b39dab91e106c7a877b677e64ef1 (diff) | |
parent | 938a8008a61ecb6e975aa974dbf30ea7e1f298e2 (diff) | |
download | bionic-5b39a44575e01ecf65397ffb7518efc3c65a6d8b.zip bionic-5b39a44575e01ecf65397ffb7518efc3c65a6d8b.tar.gz bionic-5b39a44575e01ecf65397ffb7518efc3c65a6d8b.tar.bz2 |
Merge "Fix mbsrtowcs(3) src param for finished string." into lmp-dev
-rw-r--r-- | libc/bionic/wchar.cpp | 5 | ||||
-rw-r--r-- | tests/wchar_test.cpp | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/libc/bionic/wchar.cpp b/libc/bionic/wchar.cpp index 438ce03..524ba07 100644 --- a/libc/bionic/wchar.cpp +++ b/libc/bionic/wchar.cpp @@ -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); diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp index f052ce6..d02c4bf 100644 --- a/tests/wchar_test.cpp +++ b/tests/wchar_test.cpp @@ -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)); |