diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2015-08-04 03:53:00 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2015-08-04 03:53:00 +0000 |
commit | a91ba1260a9ca94c9756639b4a43bec5f05aa280 (patch) | |
tree | 82dbd153867a5acf1cf59099c6093864babb0fcd /clang/lib/CodeGen | |
parent | f0c627d5f8a4d006d711e1d1e0c2028fdf346d8c (diff) | |
download | bcm5719-llvm-a91ba1260a9ca94c9756639b4a43bec5f05aa280.tar.gz bcm5719-llvm-a91ba1260a9ca94c9756639b4a43bec5f05aa280.zip |
[UB] Another place where we were trying to put string data into
a BumpPtrAllocator. This at least now handles the case where there is no
concatentation without calling memcpy on a null pointer. It might be
interesting to handle the case where everything is empty without
round-tripping through the allocator, but it wasn't clear to me if the
pointer returned is significant in any way, so I've left it in
a conservatively more-correct state.
Again, found with UBSan.
llvm-svn: 243948
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 72cdac3e93b..33204fb3622 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -485,8 +485,10 @@ private: /// are concatenated. StringRef internString(StringRef A, StringRef B = StringRef()) { char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size()); - std::memcpy(Data, A.data(), A.size()); - std::memcpy(Data + A.size(), B.data(), B.size()); + if (!A.empty()) + std::memcpy(Data, A.data(), A.size()); + if (!B.empty()) + std::memcpy(Data + A.size(), B.data(), B.size()); return StringRef(Data, A.size() + B.size()); } }; |