This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fwd: g++ off-by-one bug in utf16 conversion
- From: Joseph Myers <joseph at codesourcery dot com>
- To: John Schmerge <jbschmerge at gmail dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 29 Nov 2014 01:56:47 +0000
- Subject: Re: Fwd: g++ off-by-one bug in utf16 conversion
- Authentication-results: sourceware.org; auth=none
- References: <CAL1ZCA-JS0w+qeQW2BsJq8u6geTtZWjwMQYQKBiE5wSaX3tKag at mail dot gmail dot com> <CAL1ZCA8Pz1xgJeSe7yYSkwxt6f2h95sCsjgVarLeC+ZML2+gGQ at mail dot gmail dot com>
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 <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.
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
joseph@codesourcery.com