[llvm] r349826 - [llvm-objcopy] [COFF] Avoid memcpy() with null parameters in more places. NFC.
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 20 13:36:00 PST 2018
Author: mstorsjo
Date: Thu Dec 20 13:35:59 2018
New Revision: 349826
URL: http://llvm.org/viewvc/llvm-project?rev=349826&view=rev
Log:
[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.
Modified:
llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
Modified: llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp?rev=349826&r1=349825&r2=349826&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp Thu Dec 20 13:35:59 2018
@@ -215,7 +215,7 @@ void COFFWriter::writeHeaders(bool IsBig
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 COFFWrite
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) {
More information about the llvm-commits
mailing list