From 14cfa9ae2ee25b0a633114b756b7ca0c90c69f40 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Thu, 20 Dec 2018 21:35:59 +0000 Subject: [PATCH] [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 --- llvm/tools/llvm-objcopy/COFF/Writer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/tools/llvm-objcopy/COFF/Writer.cpp b/llvm/tools/llvm-objcopy/COFF/Writer.cpp index 6cda11c8a6ba..5a461e43a555 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(Ptr)); } } @@ -237,7 +237,7 @@ template void COFFWriter::writeSymbolStringTables() { copySymbol(*reinterpret_cast(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) {