[Bug libstdc++/11305] New: basic_filebuf::_M_convert_to_external fails to convert single characters.

peturr02 at ru dot is gcc-bugzilla@gcc.gnu.org
Tue Jun 24 09:05:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11305

           Summary: basic_filebuf::_M_convert_to_external fails to convert
                    single characters.
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: peturr02 at ru dot is
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

The buffer allocated by _M_convert_to_external to hold the result of the
conversion is too small for some characters.

	  // Worst-case number of external bytes needed.
	  int __ext_multiplier = _M_codecvt->encoding();
	  if (__ext_multiplier ==  -1 || __ext_multiplier == 0)
	    __ext_multiplier = sizeof(char_type);
	  streamsize __blen = __ilen * __ext_multiplier;
	  char* __buf = static_cast<char*>(__builtin_alloca(__blen));

On my system (Redhat Linux 8.0) sizeof(wchar_t) is 4, but UTF-8 requires up to 6
bytes for each character. I believe __ext_multiplier should be set to
_M_codecvt->max_length() when _M_codecvt->encoding() == 0 to fix this.

Related to this, 27.8.1.4 p8 bullet 4 requires that if the conversion fails
because the buffer is too small, a larger buffer should be allocated before
retrying, but _M_convert_to_external currently retries with the same buffer.



More information about the Gcc-bugs mailing list