re PR libstdc++/9168 (codecvt<char, char, mbstate_t> overwrites output buffers)

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
This commit is contained in:
Paolo Carlini 2003-01-05 09:04:18 +01:00 committed by Paolo Carlini
parent c7c50494be
commit b1599033fa
3 changed files with 27 additions and 7 deletions

View 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):

View 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;

View 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