Make UTF8->UTF16 conversion null terminate output on empty input.
authorZachary Turner <zturner@google.com>
Sun, 8 Feb 2015 18:08:51 +0000 (18:08 +0000)
committerZachary Turner <zturner@google.com>
Sun, 8 Feb 2015 18:08:51 +0000 (18:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228527 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/ConvertUTFWrapper.cpp

index 4feff01b08ed70e71ca2d338772b2887733feb86..1bbef233b82f4437d488c0a606fdda7cf5a5dc9d 100644 (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());