Skip to content

Commit ddd493c

Browse files
committed
Added test
1 parent 688b4db commit ddd493c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/tr1/tests/cwchar2/test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#define TEST_NAME "<cwchar>, part 2"
66

77
#include "tdefs.h"
8+
#include <clocale>
89
#include <cwchar>
10+
#include <errno.h>
911
#include <limits.h>
1012
#include <time.h>
1113

@@ -50,6 +52,27 @@ void test_cpp() { // test C++ header
5052
CHECK_INT(STDx mbrtowc(&wc, abc + 3, 9, &mbst), 0);
5153
CHECK_INT(wc, L'\0');
5254

55+
{ // UTF-8 overlong sequences should be rejected
56+
const char overlong_nul[] = "\xC0\x80";
57+
const char overlong_A[] = "\xC1\x81";
58+
59+
if (std::setlocale(LC_CTYPE, ".UTF-8") != nullptr) {
60+
STDx mbstate_t utf8_state{};
61+
wchar_t wide_out;
62+
63+
errno = 0;
64+
CHECK_INT(STDx mbrtowc(&wide_out, overlong_nul, sizeof(overlong_nul) - 1, &utf8_state), -1);
65+
CHECK_INT(errno, EILSEQ);
66+
67+
utf8_state = STDx mbstate_t{};
68+
errno = 0;
69+
CHECK_INT(STDx mbrtowc(&wide_out, overlong_A, sizeof(overlong_A) - 1, &utf8_state), -1);
70+
CHECK_INT(errno, EILSEQ);
71+
72+
std::setlocale(LC_CTYPE, "C");
73+
}
74+
}
75+
5376
CHECK(STDx mbsinit(&mbst) != 0);
5477
pc = &abc[0];
5578
CHECK_INT(STDx mbsrtowcs(wcs, &pc, 10, &mbst), 3);

0 commit comments

Comments
 (0)