From 66dfef17b8da7c89e20f32d4f0f4a04691b79768 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 14 Sep 2012 21:17:41 +0000 Subject: [PATCH] In StringLiteral::setString make sure that we copy the number of bytes of the buffer and not the size of the string, otherwise we may overwrite the buffer if there is a mismatch between the size of the string and the CharByteWidth, and assertions are disabled. The bug where this could occur was fixed in r163931. Related to rdar://12069503 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163939 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index ea82cf7531..74308a0093 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -784,19 +784,19 @@ void StringLiteral::setString(ASTContext &C, StringRef Str, switch(CharByteWidth) { case 1: { char *AStrData = new (C) char[Length]; - std::memcpy(AStrData,Str.data(),Str.size()); + std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asChar = AStrData; break; } case 2: { uint16_t *AStrData = new (C) uint16_t[Length]; - std::memcpy(AStrData,Str.data(),Str.size()); + std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt16 = AStrData; break; } case 4: { uint32_t *AStrData = new (C) uint32_t[Length]; - std::memcpy(AStrData,Str.data(),Str.size()); + std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt32 = AStrData; break; } -- 2.40.0