r243947 - [UB] When attaching empty strings to the AST, use an empty StringRef
Chandler Carruth
chandlerc at gmail.com
Mon Aug 3 20:52:58 PDT 2015
Author: chandlerc
Date: Mon Aug 3 22:52:58 2015
New Revision: 243947
URL: http://llvm.org/viewvc/llvm-project?rev=243947&view=rev
Log:
[UB] When attaching empty strings to the AST, use an empty StringRef
rather than forcing the bump pointer allocator to produce a viable
pointer. This also fixes UB when we would try to memcpy from the null
incoming StringRef.
Modified:
cfe/trunk/lib/AST/Stmt.cpp
Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=243947&r1=243946&r2=243947&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Mon Aug 3 22:52:58 2015
@@ -724,6 +724,8 @@ MSAsmStmt::MSAsmStmt(const ASTContext &C
}
static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
+ if (str.empty())
+ return StringRef();
size_t size = str.size();
char *buffer = new (C) char[size];
memcpy(buffer, str.data(), size);
More information about the cfe-commits
mailing list