This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Fix libstdc++/9169


Hi,

the below fixes the problem by dealing with the noconv case
as already done for the always_noconv case a few lines above.

Tested x86-linux. Ok trunk and 3_3?

Paolo.

//////////
2003-02-16  Paolo Carlini  <pcarlini@unitus.it>

	PR libstdc++/9169
	* include/bits/fstream.tcc (_M_convert_to_external):
	Deal correctly with noconv, as prescribed by 27.8.1.4,p8.
	* testsuite/27_io/filebuf_virtuals.cc (test10): Add.
diff -urN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-orig/include/bits/fstream.tcc	2003-02-16 12:22:29.000000000 +0100
+++ libstdc++-v3/include/bits/fstream.tcc	2003-02-16 20:02:52.000000000 +0100
@@ -291,9 +291,15 @@
 	  const char_type* __iend;
 	  __res_type __r = __cvt.out(_M_state_cur, __ibuf, __ibuf + __ilen, 
 		 		     __iend, __buf, __buf + __blen, __bend);
-	  // Result == ok, partial, noconv
-	  if (__r != codecvt_base::error)
+
+	  if (__r == codecvt_base::ok || __r == codecvt_base::partial)
 	    __blen = __bend - __buf;
+	  // Similarly to the always_noconv case above.
+	  else if (__r == codecvt_base::noconv)
+	    {
+	      __buf = reinterpret_cast<char*>(__ibuf);
+	      __blen = __ilen;
+	    }
 	  // Result == error
 	  else 
 	    __blen = 0;
diff -urN libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
--- libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc	2003-02-07 12:00:35.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc	2003-02-16 20:09:11.000000000 +0100
@@ -584,6 +584,46 @@
   VERIFY( r == filebuf::traits_type::eof() );
 }
 
+class Cvt_to_upper : public std::codecvt<char, char, mbstate_t>
+{
+  bool do_always_noconv() const throw()
+  {
+    return false;
+  }
+};
+
+// libstdc++/9169
+void test10()
+{
+  using namespace std;
+  bool test = true;
+
+  locale c_loc;
+  locale loc(c_loc, new Cvt_to_upper);
+
+  string str("abcdefghijklmnopqrstuvwxyz");
+  string tmp;
+
+  {
+    ofstream out;
+    out.imbue(loc);
+    out.open("filebuf_virtuals-4.txt");
+    copy(str.begin(), str.end(),
+	 ostreambuf_iterator<char>(out));
+  }
+
+  {
+    ifstream in;
+    in.open("filebuf_virtuals-4.txt");
+    copy(istreambuf_iterator<char>(in),
+	 istreambuf_iterator<char>(),
+	 back_inserter(tmp));
+  }
+
+  VERIFY( tmp.size() == str.size() );
+  VERIFY( tmp == str );
+}
+
 main() 
 {
   test01();
@@ -597,5 +637,6 @@
   test07();
   test08();
   test09();
+  test10();
   return 0;
 }

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