aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wchar_test.cpp
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2014-07-20 11:51:26 -0700
committerDan Albert <danalbert@google.com>2014-07-21 11:45:48 -0700
commit6b55ba54eff4657cffe053b71e1c9cce2944a8a9 (patch)
treecec574487f5fe5c039a9b2acd90ea4dbe22e8066 /tests/wchar_test.cpp
parent7dd126a38ca501818b07927f310dcc0f531c0f1f (diff)
downloadandroid_bionic-6b55ba54eff4657cffe053b71e1c9cce2944a8a9.tar.gz
android_bionic-6b55ba54eff4657cffe053b71e1c9cce2944a8a9.tar.bz2
android_bionic-6b55ba54eff4657cffe053b71e1c9cce2944a8a9.zip
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
Diffstat (limited to 'tests/wchar_test.cpp')
-rw-r--r--tests/wchar_test.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp
index a5f5f63a2..f052ce6f1 100644
--- a/tests/wchar_test.cpp
+++ b/tests/wchar_test.cpp
@@ -340,8 +340,19 @@ void test_mbsrtowcs(mbstate_t* ps) {
ASSERT_EQ(static_cast<wchar_t>(0x00a2), out[1]);
ASSERT_EQ(static_cast<wchar_t>(0x20ac), out[2]);
ASSERT_EQ(static_cast<wchar_t>(0x24b62), out[3]);
+ // Check that valid has advanced to the next unread character.
ASSERT_EQ('e', *valid);
+ wmemset(out, L'x', sizeof(out) / sizeof(wchar_t));
+ ASSERT_EQ(2U, mbsrtowcs(out, &valid, 4, ps));
+ ASSERT_EQ(L'e', out[0]);
+ ASSERT_EQ(L'f', out[1]);
+ ASSERT_EQ(L'\0', out[2]);
+ // 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);
+
const char* invalid = "A" "\xc2\x20" "ef";
ASSERT_EQ(static_cast<size_t>(-1), mbsrtowcs(out, &invalid, 4, ps));
EXPECT_EQ(EILSEQ, errno);