This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libcpp/charset: close out shift states


I think this is obvious, but I'm not familiar enough with the code to
say for sure that someone doesn't call iconv() elsewhere (I couldn't
find one) and expect a pending shift state to still be valid.  We do,
however, reset the shift state at the beginning of this function.

	* charset.c (convert_using_iconv): Close out any shift states,
	returning to the initial state.

The attached test case is designed for LANG=en_US.utf8 and
-fexec-charset=CP939.  The resulting .s has the shift-in byte at the
beginning of the converted string, but not the shift-out byte at the
end.  With this patch, it has both shift bytes.

Index: charset.c
===================================================================
--- charset.c	(revision 129957)
+++ charset.c	(working copy)
@@ -567,12 +567,16 @@ convert_using_iconv (iconv_t cd, const u
 
   for (;;)
     {
       iconv (cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
       if (__builtin_expect (inbytesleft == 0, 1))
 	{
+	  /* Close out any shift states, returning to the initial state.  */
+	  if (iconv (cd, 0, 0, &outbuf, &outbytesleft) == (size_t)-1)
+	    return false;
+
 	  to->len = to->asize - outbytesleft;
 	  return true;
 	}
       if (errno != E2BIG)
 	return false;
 
begin 644 iconv-071205-1.c
M(VEN8VQU9&4@/'-T9&EO+F@^"@II;G0@;6%I;BAV;VED*2!["@H@('!R:6YT
M9B@BYI>EYIRLZ*J>YKRBY:V7YZ*ZZ*J-7&XB*3L*"G)E='5R;B`P.PH*?3L*
!"@``
`
end


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]