Fix a UBsan bot.

If we do not initialize Prefix here, Prefix.data() returns a nullptr.
Later, it is passed to memcpy. memcpy's behavior is undefined if src (or
dst) is a nullptr even if a given size is 0. That's why this code
triggered UBsan.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314368 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rui Ueyama 2017-09-28 00:27:39 +00:00
parent 5c883452a8
commit 76b3e046e7

View File

@ -127,6 +127,7 @@ static void writePaxHeader(raw_fd_ostream &OS, StringRef Path) {
// Otherwise, returns false.
static bool splitUstar(StringRef Path, StringRef &Prefix, StringRef &Name) {
if (Path.size() < sizeof(UstarHeader::Name)) {
Prefix = "";
Name = Path;
return true;
}