Make UTF8->UTF16 conversion null terminate output on empty input.

llvm-svn: 228527
This commit is contained in:
Zachary Turner 2015-02-08 18:08:51 +00:00
parent d11b013623
commit afdff425d7
1 changed files with 4 additions and 1 deletions

View File

@ -135,8 +135,11 @@ bool convertUTF8ToUTF16String(StringRef SrcUTF8,
assert(DstUTF16.empty());
// Avoid OOB by returning early on empty input.
if (SrcUTF8.empty())
if (SrcUTF8.empty()) {
DstUTF16.push_back(0);
DstUTF16.pop_back();
return true;
}
const UTF8 *Src = reinterpret_cast<const UTF8 *>(SrcUTF8.begin());
const UTF8 *SrcEnd = reinterpret_cast<const UTF8 *>(SrcUTF8.end());