From 3461133d7227f31154ca44497a44f1599e4c0aa8 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 27 Jun 2003 14:33:49 +0200 Subject: Nathan C. 2003-06-27 Paolo Carlini Nathan C. Myers PR libstdc++/9178 * include/bits/fstream.tcc (_M_underflow): Properly estimate the worst-case number of external bytes for a given get area. * testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc: New. 2003-06-27 Paolo Carlini Petur Runolfsson PR libstdc++/11305 * include/bits/fstream.tcc (overflow): Properly estimate the worst-case number of external bytes for a given put area (by using codecvt::max_length()). * testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1: New. * testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2: New. * testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3: New. * testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4: New. Co-Authored-By: Nathan C. Myers Co-Authored-By: Petur Runolfsson From-SVN: r68566 --- libstdc++-v3/include/bits/fstream.tcc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'libstdc++-v3/include') diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index 1568b60..3d6fb96 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -213,16 +213,19 @@ namespace std } else { - char* __buf = static_cast(__builtin_alloca(__buflen)); - __elen = _M_file.xsgetn(__buf, __buflen); - - const char* __eend; + // Worst-case number of external bytes. + // XXX Not done encoding() == -1. + const streamsize __blen = __buflen * _M_codecvt->max_length(); + char* __buf = static_cast(__builtin_alloca(__blen)); + __elen = _M_file.xsgetn(__buf, __blen); + + const char* __eend; char_type* __iend; codecvt_base::result __r; __r = _M_codecvt->in(_M_state_cur, __buf, __buf + __elen, __eend, this->eback(), this->eback() + __buflen, __iend); - if (__r == codecvt_base::ok) + if (__r == codecvt_base::ok || __r == codecvt_base::partial) __ilen = __iend - this->eback(); else if (__r == codecvt_base::noconv) { @@ -391,11 +394,10 @@ namespace std else { // 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; + // XXX Not done encoding() == -1. + streamsize __blen = __ilen * _M_codecvt->max_length(); char* __buf = static_cast(__builtin_alloca(__blen)); + char* __bend; const char_type* __iend; codecvt_base::result __r; -- cgit v1.1