Fix alignment bugs in std::codecvt_utf16
commite596bd680a5e6fc56a4bcf668d7bd958b3c9df25
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 17 Mar 2017 19:28:05 +0000 (17 19:28 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 17 Mar 2017 19:28:05 +0000 (17 19:28 +0000)
tree0e22d701b0437cb98ff145680df2d6dab207e8bb
parent9178128289cf590bcc84b6775519934255dba917
Fix alignment bugs in std::codecvt_utf16

* src/c++11/codecvt.cc (range): Add non-type template parameter and
define oerloaded operators for reading and writing code units.
(range<Elem, false>): Define partial specialization for accessing
wide characters in potentially unaligned byte ranges.
(ucs2_span(const char16_t*, const char16_t*, ...))
(ucs4_span(const char16_t*, const char16_t*, ...)): Change parameters
to range<const char16_t, false> in order to avoid unaligned reads.
(__codecvt_utf16_base<char16_t>::do_out)
(__codecvt_utf16_base<char32_t>::do_out)
(__codecvt_utf16_base<wchar_t>::do_out): Use range specialization for
unaligned data to avoid unaligned writes.
(__codecvt_utf16_base<char16_t>::do_in)
(__codecvt_utf16_base<char32_t>::do_in)
(__codecvt_utf16_base<wchar_t>::do_in): Likewise for writes. Return
error if there are unprocessable trailing bytes.
(__codecvt_utf16_base<char16_t>::do_length)
(__codecvt_utf16_base<char32_t>::do_length)
(__codecvt_utf16_base<wchar_t>::do_length): Pass arguments of type
range<const char16_t, false> to span functions.
* testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@246245 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/src/c++11/codecvt.cc
libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/79980.cc
libstdc++-v3/testsuite/22_locale/codecvt/codecvt_utf16/misaligned.cc [new file with mode: 0644]