Fixed a bug in wstring_convert concerning zero-length inputs. Thanks to Jonathan Coxhead for reporting this bug.

llvm-svn: 160136
This commit is contained in:
Howard Hinnant 2012-07-12 18:07:41 +00:00
parent 41f88aad98
commit 9146984e73
3 changed files with 8 additions and 2 deletions

View File

@ -3920,7 +3920,8 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
if (__cvtptr_ != nullptr)
{
wide_string __ws(2*(__frm_end - __frm), _Elem());
__ws.resize(__ws.capacity());
if (__frm != __frm_end)
__ws.resize(__ws.capacity());
codecvt_base::result __r = codecvt_base::ok;
state_type __st = __cvtstate_;
if (__frm != __frm_end)
@ -3980,7 +3981,8 @@ wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
if (__cvtptr_ != nullptr)
{
byte_string __bs(2*(__frm_end - __frm), char());
__bs.resize(__bs.capacity());
if (__frm != __frm_end)
__bs.resize(__bs.capacity());
codecvt_base::result __r = codecvt_base::ok;
state_type __st = __cvtstate_;
if (__frm != __frm_end)

View File

@ -33,5 +33,7 @@ int main()
assert(ws == L"\x40003");
ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
assert(ws == L"\x40003");
ws = myconv.from_bytes("");
assert(ws.size() == 0);
}
}

View File

@ -33,5 +33,7 @@ int main()
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
assert(bs == "\xF1\x80\x80\x83");
bs = myconv.to_bytes(L"");
assert(bs.size() == 0);
}
}