summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/MemoryBuffer.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-08-04 01:00:56 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-08-04 01:00:56 +0000
commit1c156f737e03318f2863aa02fd098dca24a85544 (patch)
tree94b5abad51f7c1aab94f5306ba21c9274203d07d /llvm/lib/Support/MemoryBuffer.cpp
parente8ea9ac32bb759e915fceef626bdd65028838852 (diff)
downloadbcm5719-llvm-1c156f737e03318f2863aa02fd098dca24a85544.tar.gz
bcm5719-llvm-1c156f737e03318f2863aa02fd098dca24a85544.zip
[UB] Fix yet another use of memcpy with a null pointer argument. I think
this is the last of them in my build of LLVM. Haven't tried Clang yet. Found via UBSan. llvm-svn: 243934
Diffstat (limited to 'llvm/lib/Support/MemoryBuffer.cpp')
-rw-r--r--llvm/lib/Support/MemoryBuffer.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 98862e96b74..d09ef3a4c0b 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -57,7 +57,8 @@ void MemoryBuffer::init(const char *BufStart, const char *BufEnd,
/// CopyStringRef - Copies contents of a StringRef into a block of memory and
/// null-terminates it.
static void CopyStringRef(char *Memory, StringRef Data) {
- memcpy(Memory, Data.data(), Data.size());
+ if (!Data.empty())
+ memcpy(Memory, Data.data(), Data.size());
Memory[Data.size()] = 0; // Null terminate string.
}
OpenPOWER on IntegriCloud