Thanks, I've added a testcase and committed this patch.  Bootstrapped
with no regressions on x86_64-unknown-linux-gnu.

libcpp:
2014-11-29  John Schmerge  <jbschme...@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  <jos...@codesourcery.com>

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

Index: gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C  (revision 0)
+++ gcc/testsuite/g++.dg/cpp/utf16-pr41698-1.C  (working copy)
@@ -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: libcpp/charset.c
===================================================================
--- libcpp/charset.c    (revision 218163)
+++ libcpp/charset.c    (working copy)
@@ -353,7 +353,7 @@ one_utf8_to_utf16 (iconv_t bigend, const uchar **i
       return EILSEQ;
     }
 
-  if (s < 0xFFFF)
+  if (s <= 0xFFFF)
     {
       if (*outbytesleftp < 2)
        {

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to