diff options
author | Martin Storsjo <martin@martin.st> | 2018-12-20 21:35:59 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2018-12-20 21:35:59 +0000 |
commit | 14cfa9ae2ee25b0a633114b756b7ca0c90c69f40 (patch) | |
tree | 2039b0b69d7d935d0bc809973885556d45035d4d | |
parent | 303b2333e40318adf22f721297c42902466fa3b8 (diff) | |
download | bcm5719-llvm-14cfa9ae2ee25b0a633114b756b7ca0c90c69f40.tar.gz bcm5719-llvm-14cfa9ae2ee25b0a633114b756b7ca0c90c69f40.zip |
[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
-rw-r--r-- | llvm/tools/llvm-objcopy/COFF/Writer.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/tools/llvm-objcopy/COFF/Writer.cpp b/llvm/tools/llvm-objcopy/COFF/Writer.cpp index 6cda11c8a6b..5a461e43a55 100644 --- a/llvm/tools/llvm-objcopy/COFF/Writer.cpp +++ b/llvm/tools/llvm-objcopy/COFF/Writer.cpp @@ -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) { |