Author: chandlerc Date: Mon Aug 3 22:53:00 2015 New Revision: 243948 URL: http://llvm.org/viewvc/llvm-project?rev=243948&view=rev Log: [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. Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=243948&r1=243947&r2=243948&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Aug 3 22:53:00 2015 @@ -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()); } }; _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits