[llvm-objcopy] [COFF] Avoid memcpy() with null parameters in more places. NFC.

This fixes all cases of errors in asan+ubsan builds.

Also use std::copy instead of if+memcpy in the previously updated spot,
for consistency.

llvm-svn: 349826
This commit is contained in:
Martin Storsjo 2018-12-20 21:35:59 +00:00
parent 303b2333e4
commit 14cfa9ae2e
1 changed files with 4 additions and 4 deletions

View File

@ -215,7 +215,7 @@ void COFFWriter::writeHeaders(bool IsBigObj) {
void COFFWriter::writeSections() {
for (const auto &S : Obj.Sections) {
uint8_t *Ptr = Buf.getBufferStart() + S.Header.PointerToRawData;
memcpy(Ptr, S.Contents.data(), S.Contents.size());
std::copy(S.Contents.begin(), S.Contents.end(), Ptr);
// For executable sections, pad the remainder of the raw data size with
// 0xcc, which is int3 on x86.
@ -225,8 +225,8 @@ void COFFWriter::writeSections() {
S.Header.SizeOfRawData - S.Contents.size());
Ptr += S.Header.SizeOfRawData;
if (!S.Relocs.empty())
memcpy(Ptr, S.Relocs.data(), S.Relocs.size() * sizeof(coff_relocation));
std::copy(S.Relocs.begin(), S.Relocs.end(),
reinterpret_cast<coff_relocation *>(Ptr));
}
}
@ -237,7 +237,7 @@ template <class SymbolTy> void COFFWriter::writeSymbolStringTables() {
copySymbol<SymbolTy, coff_symbol32>(*reinterpret_cast<SymbolTy *>(Ptr),
S.Sym);
Ptr += sizeof(SymbolTy);
memcpy(Ptr, S.AuxData.data(), S.AuxData.size());
std::copy(S.AuxData.begin(), S.AuxData.end(), Ptr);
Ptr += S.AuxData.size();
}
if (StrTabBuilder.getSize() > 4 || !Obj.IsPE) {