re PR libstdc++/9168 (codecvt<char, char, mbstate_t> overwrites output buffers)
authorPaolo Carlini <pcarlini@unitus.it>
Sun, 5 Jan 2003 08:04:18 +0000 (09:04 +0100)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 5 Jan 2003 08:04:18 +0000 (08:04 +0000)
2003-01-05  Paolo Carlini <pcarlini@unitus.it>

PR libstdc++/9168
* src/codecvt.cc
(codecvt<char, char, mbstate_t>::do_in, do_out):
Implement the resolution of DR19 (TC).
* testsuite/22_locale/codecvt_members_char_char.cc
(test01): Tweak.

From-SVN: r60901

libstdc++-v3/ChangeLog
libstdc++-v3/src/codecvt.cc
libstdc++-v3/testsuite/22_locale/codecvt_members_char_char.cc

index ba62559eae5e4cb62b475e3de02fd187b8bcac3b..75dc14ba3044ac1db1e40cb97fe25b41076f49b9 100644 (file)
@@ -1,3 +1,12 @@
+2003-01-05  Paolo Carlini <pcarlini@unitus.it>
+
+       PR libstdc++/9168
+       * src/codecvt.cc
+       (codecvt<char, char, mbstate_t>::do_in, do_out):
+       Implement the resolution of DR19 (TC).
+       * testsuite/22_locale/codecvt_members_char_char.cc
+       (test01): Tweak.
+
 2003-01-02  Jason Merrill  <jason@redhat.com>
 
        * config/cpu/i486/atomicity.h (__exchange_and_add, __atomic_add):
index e86d15b9397a85704c6d3a980494004038460e4d..b6ccc43acc95a4b097662291108b79ce1566c44d 100644 (file)
@@ -64,8 +64,9 @@ namespace std
         extern_type* __to, extern_type* __to_end, 
         extern_type*& __to_next) const
   { 
-    size_t __len = std::min(__from_end - __from, __to_end - __to);
-    memcpy(__to, __from, __len);
+    // _GLIBCPP_RESOLVE_LIB_DEFECTS
+    // According to the resolution of DR19, "If returns noconv [...]
+    // there are no changes to the values in [to, to_limit)."
     __from_next = __from; 
     __to_next = __to;
     return noconv;  
@@ -86,9 +87,10 @@ namespace std
        const extern_type* __from_end, const extern_type*& __from_next,
        intern_type* __to, intern_type* __to_end, 
        intern_type*& __to_next) const
-  { 
-    size_t __len = std::min(__from_end - __from, __to_end - __to);
-    memcpy(__to, __from, __len);
+  {
+    // _GLIBCPP_RESOLVE_LIB_DEFECTS
+    // According to the resolution of DR19, "If returns noconv [...]
+    // there are no changes to the values in [to, to_limit)."
     __from_next = __from; 
     __to_next = __to;
     return noconv;  
index 9cf4e7d5c7076420df1e6263f447f35a16ac4143..b2acb675351d98a818643bad682dbb34d0a6dcad 100644 (file)
@@ -36,25 +36,33 @@ void test01()
   const char*          from_next;
   int                  size = 25;
   char*                c_arr = new char[size];
+  char*                 c_ref = new char[size];
   char*                        to_next;
 
   locale               loc;
   c_codecvt::state_type state;
   const c_codecvt*     cvt = &use_facet<c_codecvt>(loc); 
 
+  // According to the resolution of DR19 (see also libstd++/9168), in
+  // case of degenerate conversion ('noconv'), "there are no changes to
+  // the values in [to, to_limit)."
+  memset(c_ref, 'X', size);
+
   // in
+  memset(c_arr, 'X', size);
   result r1 = cvt->in(state, c_lit, c_lit + size, from_next, 
                      c_arr, c_arr + size, to_next);
   VERIFY( r1 == codecvt_base::noconv );
-  VERIFY( !strcmp(c_arr, c_lit) ); 
+  VERIFY( !memcmp(c_arr, c_ref, size) ); 
   VERIFY( from_next == c_lit );
   VERIFY( to_next == c_arr );
 
   // out
+  memset(c_arr, 'X', size);
   result r2 = cvt->out(state, c_lit, c_lit + size, from_next, 
                       c_arr, c_arr + size, to_next);
   VERIFY( r2 == codecvt_base::noconv );
-  VERIFY( !strcmp(c_arr, c_lit) ); 
+  VERIFY( !memcmp(c_arr, c_ref, size) ); 
   VERIFY( from_next == c_lit );
   VERIFY( to_next == c_arr );
 
@@ -77,6 +85,7 @@ void test01()
   VERIFY( k == 1 );
 
   delete [] c_arr;
+  delete [] c_ref;
 }
 
 // libstdc++/5280