]> granicus.if.org Git - clang/commitdiff
[UB] Another place where we were trying to put string data into
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Aug 2015 03:53:00 +0000 (03:53 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Aug 2015 03:53:00 +0000 (03:53 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243948 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.h

index 72cdac3e93b9276e895349de9897196911984864..33204fb3622e91f8aa685336ebb98744bee69c85 100644 (file)
@@ -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());
   }
 };