From b1599033fa7812428362e73975a87b0bc28ff3a3 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sun, 5 Jan 2003 09:04:18 +0100 Subject: [PATCH] re PR libstdc++/9168 (codecvt overwrites output buffers) 2003-01-05 Paolo Carlini PR libstdc++/9168 * src/codecvt.cc (codecvt::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 | 9 +++++++++ libstdc++-v3/src/codecvt.cc | 12 +++++++----- .../22_locale/codecvt_members_char_char.cc | 13 +++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ba62559eae5..75dc14ba304 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2003-01-05 Paolo Carlini + + PR libstdc++/9168 + * src/codecvt.cc + (codecvt::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 * config/cpu/i486/atomicity.h (__exchange_and_add, __atomic_add): diff --git a/libstdc++-v3/src/codecvt.cc b/libstdc++-v3/src/codecvt.cc index e86d15b9397..b6ccc43acc9 100644 --- a/libstdc++-v3/src/codecvt.cc +++ b/libstdc++-v3/src/codecvt.cc @@ -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; diff --git a/libstdc++-v3/testsuite/22_locale/codecvt_members_char_char.cc b/libstdc++-v3/testsuite/22_locale/codecvt_members_char_char.cc index 9cf4e7d5c70..b2acb675351 100644 --- a/libstdc++-v3/testsuite/22_locale/codecvt_members_char_char.cc +++ b/libstdc++-v3/testsuite/22_locale/codecvt_members_char_char.cc @@ -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(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 -- 2.30.2