Fix off-by-one bug in utf16 conversion (PR preprocessor/41698).
authorJoseph Myers <jsm28@gcc.gnu.org>
Sat, 29 Nov 2014 01:56:06 +0000 (01:56 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sat, 29 Nov 2014 01:56:06 +0000 (01:56 +0000)
libcpp:
2014-11-29  John Schmerge  <jbschmerge@gmail.com>

PR preprocessor/41698
* charset.c (one_utf8_to_utf16): Do not produce surrogate pairs
for 0xffff.

gcc/testsuite:
2014-11-29  Joseph Myers  <joseph@codesourcery.com>

PR preprocessor/41698
* gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C: New test.

From-SVN: r218179

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C [new file with mode: 0644]
libcpp/ChangeLog
libcpp/charset.c

index 31bcf5cd6837801c0ec77dc77331119921eeb8a5..888c5964c9ff23893b11702c1a20454ce27edaf1 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-29  Joseph Myers  <joseph@codesourcery.com>
+
+       PR preprocessor/41698
+       * gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C: New test.
+
 2014-11-28  Vladimir Makarov  <vmakarov@redhat.com>
 
        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 (file)
index 0000000..e60f25b
--- /dev/null
@@ -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);
+}
index e04130a8df738bba3809a52e03ef99c1e3e68653..f9a04f9376e4e2c0f9f125d66078ceee98b8ec62 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-29  John Schmerge  <jbschmerge@gmail.com>
+
+       PR preprocessor/41698
+       * charset.c (one_utf8_to_utf16): Do not produce surrogate pairs
+       for 0xffff.
+
 2014-11-25  Jakub Jelinek  <jakub@redhat.com>
 
        PR preprocessor/60436
index 1064f5276332ad486ccfb75d87628fd6eafef462..a34dafbb1944f28e7afc7d6253b85083904c9f7f 100644 (file)
@@ -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)
        {