libcpp/charset: close out shift states
Thu Dec 6 20:20:00 GMT 2007
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.
--- charset.c (revision 129957)
+++ charset.c (working copy)
@@ -567,12 +567,16 @@ convert_using_iconv (iconv_t cd, const u
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;
if (errno != E2BIG)
begin 644 iconv-071205-1.c
More information about the Gcc-patches