Open Quuxplusone opened 12 years ago
Attached test.cc
(846 bytes, text/x-c++src): testcase
committed revision 233012 to fix this problem.
I'm going to leave this bug open, though, until I figure what the correct
behavior is.
The fix merely deals with the error correctly.
As pointed out above, I think that it should return partial, not ok.
cf. http://melpon.org/wandbox/permlink/8Jo9s9qODgywSmtP
This behavior causes PR24929.
Additionally, if "from" ends with an incomplete multibyte sequence followed by a null byte, "from_next" should point the first byte of an incomplete multibyte sequence, not a null byte.
C++98 (or later) standard 22.2.1.5.2 codecvt virtual functions [lib.locale.codecvt.virtuals] p.2 says, "It always leaves the from_next and to_next pointers pointing one beyond the last element successfully converted."
I think that do_in should behave as below.
====================================================================================
codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const {
frm_nxt = frm;
to_nxt = to;
if (frm == frm_end) {
mbstate_t save_st = st;
return __mbrtowc_l(NULL, NULL, 0, &save_st, __l) == 0 ? ok : partial;
}
do {
if (to_nxt == to_end)
return partial;
size_t n = __mbrtowc_l(to_nxt, frm_nxt, frm_end - frm_nxt, &st, __l);
switch (n) {
case size_t(-1):
return error;
case size_t(-2):
frm_nxt = frm_end;
return partial;
case 0:
++frm_nxt;
break;
default:
frm_nxt += n;
break;
}
++to_nxt;
} while (frm_nxt != frm_end);
return ok;
}
====================================================================================
test.cc
(846 bytes, text/x-c++src)