Fix UBSan bot by not passing NULL into memcpy src.

Summary:
UBSan complains like the following:
tools/lld/COFF/Writer.cpp:97:15: runtime error: null pointer passed as argument 2, which is declared to never be null

The reason is that the vector could be empty.

Reviewers: rsmith

Subscribers: Eugene.Zelenko, kcc

Differential Revision: https://reviews.llvm.org/D24050

llvm-svn: 280259
This commit is contained in:
Ivan Krasin 2016-08-31 17:23:05 +00:00
parent 1e9d3d3b40
commit 8baccc2f19
1 changed files with 2 additions and 1 deletions

View File

@ -93,6 +93,7 @@ class CVDebugRecordChunk : public Chunk {
// variable sized field (PDB Path)
auto *P = reinterpret_cast<char *>(B + OutputSectionOff + sizeof(*R));
if (!Config->PDBPath.empty())
memcpy(P, Config->PDBPath.data(), Config->PDBPath.size());
P[Config->PDBPath.size()] = '\0';
}