File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -115,3 +115,20 @@ TEST_F(LlvmLibcMBSToWCSTest, NullDestination) {
115115 // Null destination should ignore len and read till end of string
116116 ASSERT_EQ (static_cast <int >(n), 4 );
117117}
118+
119+ TEST_F (LlvmLibcMBSToWCSTest, ErrnoChecks) {
120+ // Two laughing cat emojis and invalid 3rd mb char (3rd byte of it)
121+ const char *src =
122+ " \xf0\x9f\x98\xb9\xf0\x9f\x98\xb9\xf0\x9f\xf0\xb9\xf0\x9f\x98\xb9 " ;
123+ wchar_t dest[5 ];
124+ // First two bytes are valid --> should not set errno
125+ size_t n = LIBC_NAMESPACE::mbstowcs (dest, src, 2 );
126+ ASSERT_ERRNO_SUCCESS ();
127+ ASSERT_EQ (static_cast <int >(n), 2 );
128+ ASSERT_EQ (static_cast <int >(dest[0 ]), 128569 );
129+ ASSERT_EQ (static_cast <int >(dest[1 ]), 128569 );
130+ // Trying to read the 3rd byte should set errno
131+ n = LIBC_NAMESPACE::mbstowcs (dest, src, 2 );
132+ ASSERT_ERRNO_EQ (EILSEQ);
133+ ASSERT_EQ (static_cast <int >(n), -1 );
134+ }
You can’t perform that action at this time.
0 commit comments