From: Joseph Myers Date: Sat, 29 Nov 2014 01:56:06 +0000 (+0000) Subject: Fix off-by-one bug in utf16 conversion (PR preprocessor/41698). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=81fee4a708e49a075602b0b4f89793ad9ed22f01;p=gcc.git Fix off-by-one bug in utf16 conversion (PR preprocessor/41698). libcpp: 2014-11-29 John Schmerge PR preprocessor/41698 * charset.c (one_utf8_to_utf16): Do not produce surrogate pairs for 0xffff. gcc/testsuite: 2014-11-29 Joseph Myers PR preprocessor/41698 * gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C: New test. From-SVN: r218179 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 31bcf5cd683..888c5964c9f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-11-29 Joseph Myers + + PR preprocessor/41698 + * gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C: New test. + 2014-11-28 Vladimir Makarov PR target/64061 diff --git a/gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C b/gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C new file mode 100644 index 00000000000..e60f25b52a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C @@ -0,0 +1,15 @@ +// PR 41698: off-by-one error in UTF-16 encoding. + +// { dg-do run { target c++11 } } + +extern "C" void abort (void); +extern "C" void exit (int); + +int +main () +{ + char16_t s[] = u"\uffff"; + if (sizeof s != 2 * sizeof (char16_t) || s[0] != 0xffff || s[1] != 0) + abort (); + exit (0); +} diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index e04130a8df7..f9a04f9376e 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,9 @@ +2014-11-29 John Schmerge + + PR preprocessor/41698 + * charset.c (one_utf8_to_utf16): Do not produce surrogate pairs + for 0xffff. + 2014-11-25 Jakub Jelinek PR preprocessor/60436 diff --git a/libcpp/charset.c b/libcpp/charset.c index 1064f527633..a34dafbb194 100644 --- a/libcpp/charset.c +++ b/libcpp/charset.c @@ -353,7 +353,7 @@ one_utf8_to_utf16 (iconv_t bigend, const uchar **inbufp, size_t *inbytesleftp, return EILSEQ; } - if (s < 0xFFFF) + if (s <= 0xFFFF) { if (*outbytesleftp < 2) {