diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2015-08-04 03:52:58 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2015-08-04 03:52:58 +0000 |
commit | 9bf6d3458b05900ba9836e92b17081c7e0f01230 (patch) | |
tree | d2689ec6d81b9794cece4b111f98ff0894e7c215 /lib/AST/Stmt.cpp | |
parent | 9bf4b5f6264515fde32523af77dbea5557b1ec7a (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243947 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Stmt.cpp')
-rw-r--r-- | lib/AST/Stmt.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 7aab1371a2..181a3b4666 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -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); |