Fix alignment bugs in std::codecvt_utf16
authorJonathan Wakely <jwakely@redhat.com>
Fri, 17 Mar 2017 19:28:05 +0000 (19:28 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 17 Mar 2017 19:28:05 +0000 (19:28 +0000)
commitd951e75dfe83b86dd2c46c7835e03bbf04b29278
tree0e22d701b0437cb98ff145680df2d6dab207e8bb
parentd1a73b0baead836a8d813a6a63459ef87a270bba
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.

From-SVN: r246245
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]