Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

output buffer do not needed to be empty. #19

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Support/ConvertUTFWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ bool hasUTF16ByteOrderMark(ArrayRef<char> S) {
}

bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
assert(Out.empty());

// Error out on an uneven byte count.
if (SrcBytes.size() % 2)
return false;

// Avoid OOB by returning early on empty input.
if (SrcBytes.empty())
if (SrcBytes.empty()) {
Out.clear();
return true;
}

const UTF16 *Src = reinterpret_cast<const UTF16 *>(SrcBytes.begin());
const UTF16 *SrcEnd = reinterpret_cast<const UTF16 *>(SrcBytes.end());
Expand Down Expand Up @@ -140,10 +141,9 @@ bool convertUTF16ToUTF8String(ArrayRef<UTF16> Src, std::string &Out)

bool convertUTF8ToUTF16String(StringRef SrcUTF8,
SmallVectorImpl<UTF16> &DstUTF16) {
assert(DstUTF16.empty());

// Avoid OOB by returning early on empty input.
if (SrcUTF8.empty()) {
DstUTF16.clear();
DstUTF16.push_back(0);
DstUTF16.pop_back();
return true;
Expand Down