]> granicus.if.org Git - clang/commitdiff
[UB] When attaching empty strings to the AST, use an empty StringRef
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Aug 2015 03:52:58 +0000 (03:52 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Aug 2015 03:52:58 +0000 (03:52 +0000)
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.

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

lib/AST/Stmt.cpp

index 7aab1371a28211cf54acbecb87c97151195bd34f..181a3b4666b961e7af28ccf00eb2205fc17aa702 100644 (file)
@@ -724,6 +724,8 @@ MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
 }
 
 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);