}
}
+static std::unique_ptr<ValueProfData> AllocValueProfData(uint32_t TotalSize) {
+ return std::unique_ptr<ValueProfData>(new (::operator new(TotalSize))
+ ValueProfData());
+}
+
std::unique_ptr<ValueProfData>
ValueProfData::serializeFrom(const InstrProfRecord &Record) {
uint32_t TotalSize = getSize(Record);
- void *RawMem = ::operator new(TotalSize);
- ValueProfData *VPDMem = new (RawMem) ValueProfData();
- std::unique_ptr<ValueProfData> VPD(VPDMem);
+
+ std::unique_ptr<ValueProfData> VPD = AllocValueProfData(TotalSize);
VPD->TotalSize = TotalSize;
VPD->NumValueKinds = Record.getNumValueKinds();
if (TotalSize % sizeof(uint64_t))
return instrprof_error::malformed;
- std::unique_ptr<ValueProfData> VPD(
- reinterpret_cast<ValueProfData *>(new char[TotalSize]));
+ std::unique_ptr<ValueProfData> VPD = AllocValueProfData(TotalSize);
+
memcpy(VPD.get(), D, TotalSize);
// Byte swap.
VPD->swapBytesToHost(Endianness);
if (VR->Kind > IPVK_Last)
return instrprof_error::malformed;
VR = VR->getNext();
- if ((char *)VR - (char *)VPD.get() > TotalSize)
+ if ((char *)VR - (char *)VPD.get() > (ptrdiff_t)TotalSize)
return instrprof_error::malformed;
}