summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2014-07-31 20:52:19 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-07-30 11:26:00 +0000
commit447fe1c23bc5adaded9a51d3b58f3adaf2cce7b3 (patch)
treef4630dd8581b62020996f5f30636e593ac79c9b4
parent36bacd237de931c48714d1a8aa4aa9522283e407 (diff)
parentb6cc8e00cd562bd0f81fe44a6bc646540a862f32 (diff)
downloadbionic-447fe1c23bc5adaded9a51d3b58f3adaf2cce7b3.zip
bionic-447fe1c23bc5adaded9a51d3b58f3adaf2cce7b3.tar.gz
bionic-447fe1c23bc5adaded9a51d3b58f3adaf2cce7b3.tar.bz2
Merge "Fix mbsrtowcs(3) src param for finished string."
-rw-r--r--libc/bionic/wchar.cpp5
-rw-r--r--tests/wchar_test.cpp2
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));