From: Xinliang David Li Date: Wed, 11 Nov 2015 19:31:53 +0000 (+0000) Subject: Refactoring and fix another instance of asan error X-Git-Tag: android-x86-7.1-r4~41571 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3e07540b570333a26f11814f16acdbaa29853e81;p=android-x86%2Fexternal-llvm.git Refactoring and fix another instance of asan error git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252783 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 4f7328279e2..ddd23014673 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -244,12 +244,17 @@ void ValueProfData::deserializeTo(InstrProfRecord &Record, } } +static ValueProfData *AllocValueProfData(uint32_t TotalSize) { + void *RawMem = ::operator new(TotalSize); + ValueProfData *VPDMem = new (RawMem) ValueProfData(); + return VPDMem; +} + std::unique_ptr ValueProfData::serializeFrom(const InstrProfRecord &Record) { uint32_t TotalSize = getSize(Record); - void *RawMem = ::operator new(TotalSize); - ValueProfData *VPDMem = new (RawMem) ValueProfData(); - std::unique_ptr VPD(VPDMem); + + std::unique_ptr VPD(AllocValueProfData(TotalSize)); VPD->TotalSize = TotalSize; VPD->NumValueKinds = Record.getNumValueKinds(); @@ -285,8 +290,8 @@ ValueProfData::getValueProfData(const unsigned char *D, if (TotalSize % sizeof(uint64_t)) return instrprof_error::malformed; - std::unique_ptr VPD( - reinterpret_cast(new char[TotalSize])); + std::unique_ptr VPD(AllocValueProfData(TotalSize)); + memcpy(VPD.get(), D, TotalSize); // Byte swap. VPD->swapBytesToHost(Endianness);