Commit b1599033 by Paolo Carlini Committed by Paolo Carlini

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
parent c7c50494
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> 2003-01-02 Jason Merrill <jason@redhat.com>
* config/cpu/i486/atomicity.h (__exchange_and_add, __atomic_add): * config/cpu/i486/atomicity.h (__exchange_and_add, __atomic_add):
......
...@@ -64,8 +64,9 @@ namespace std ...@@ -64,8 +64,9 @@ namespace std
extern_type* __to, extern_type* __to_end, extern_type* __to, extern_type* __to_end,
extern_type*& __to_next) const extern_type*& __to_next) const
{ {
size_t __len = std::min(__from_end - __from, __to_end - __to); // _GLIBCPP_RESOLVE_LIB_DEFECTS
memcpy(__to, __from, __len); // According to the resolution of DR19, "If returns noconv [...]
// there are no changes to the values in [to, to_limit)."
__from_next = __from; __from_next = __from;
__to_next = __to; __to_next = __to;
return noconv; return noconv;
...@@ -86,9 +87,10 @@ namespace std ...@@ -86,9 +87,10 @@ namespace std
const extern_type* __from_end, const extern_type*& __from_next, const extern_type* __from_end, const extern_type*& __from_next,
intern_type* __to, intern_type* __to_end, intern_type* __to, intern_type* __to_end,
intern_type*& __to_next) const intern_type*& __to_next) const
{ {
size_t __len = std::min(__from_end - __from, __to_end - __to); // _GLIBCPP_RESOLVE_LIB_DEFECTS
memcpy(__to, __from, __len); // According to the resolution of DR19, "If returns noconv [...]
// there are no changes to the values in [to, to_limit)."
__from_next = __from; __from_next = __from;
__to_next = __to; __to_next = __to;
return noconv; return noconv;
......
...@@ -36,25 +36,33 @@ void test01() ...@@ -36,25 +36,33 @@ void test01()
const char* from_next; const char* from_next;
int size = 25; int size = 25;
char* c_arr = new char[size]; char* c_arr = new char[size];
char* c_ref = new char[size];
char* to_next; char* to_next;
locale loc; locale loc;
c_codecvt::state_type state; c_codecvt::state_type state;
const c_codecvt* cvt = &use_facet<c_codecvt>(loc); 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 // in
memset(c_arr, 'X', size);
result r1 = cvt->in(state, c_lit, c_lit + size, from_next, result r1 = cvt->in(state, c_lit, c_lit + size, from_next,
c_arr, c_arr + size, to_next); c_arr, c_arr + size, to_next);
VERIFY( r1 == codecvt_base::noconv ); VERIFY( r1 == codecvt_base::noconv );
VERIFY( !strcmp(c_arr, c_lit) ); VERIFY( !memcmp(c_arr, c_ref, size) );
VERIFY( from_next == c_lit ); VERIFY( from_next == c_lit );
VERIFY( to_next == c_arr ); VERIFY( to_next == c_arr );
// out // out
memset(c_arr, 'X', size);
result r2 = cvt->out(state, c_lit, c_lit + size, from_next, result r2 = cvt->out(state, c_lit, c_lit + size, from_next,
c_arr, c_arr + size, to_next); c_arr, c_arr + size, to_next);
VERIFY( r2 == codecvt_base::noconv ); VERIFY( r2 == codecvt_base::noconv );
VERIFY( !strcmp(c_arr, c_lit) ); VERIFY( !memcmp(c_arr, c_ref, size) );
VERIFY( from_next == c_lit ); VERIFY( from_next == c_lit );
VERIFY( to_next == c_arr ); VERIFY( to_next == c_arr );
...@@ -77,6 +85,7 @@ void test01() ...@@ -77,6 +85,7 @@ void test01()
VERIFY( k == 1 ); VERIFY( k == 1 );
delete [] c_arr; delete [] c_arr;
delete [] c_ref;
} }
// libstdc++/5280 // libstdc++/5280
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment