From d65edd8565a52f615530b4ff31e3f8fe7c3378ef Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Sun, 8 Feb 2015 18:08:51 +0000 Subject: [PATCH] Make UTF8->UTF16 conversion null terminate output on empty input. llvm-svn: 228527 --- lib/Support/ConvertUTFWrapper.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Support/ConvertUTFWrapper.cpp b/lib/Support/ConvertUTFWrapper.cpp index 4feff01b08e..1bbef233b82 100644 --- a/lib/Support/ConvertUTFWrapper.cpp +++ b/lib/Support/ConvertUTFWrapper.cpp @@ -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(SrcUTF8.begin()); const UTF8 *SrcEnd = reinterpret_cast(SrcUTF8.end());