Skip to content

Commit

Permalink
memcpy to copy_n conversions
Browse files Browse the repository at this point in the history
The latter is more strict regarding types

Signed-off-by: Rosen Penev <[email protected]>
(cherry picked from commit 1837bf0)
  • Loading branch information
neheb authored and mergify[bot] committed Jul 17, 2023
1 parent 3288ed0 commit d0833b5
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ AsfVideo::GUIDTag::GUIDTag(unsigned int data1, unsigned short data2, unsigned sh
}

AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
memcpy(&data1_, bytes, DWORD);
memcpy(&data2_, bytes + DWORD, WORD);
memcpy(&data3_, bytes + DWORD + WORD, WORD);
std::copy_n(bytes, DWORD, reinterpret_cast<uint8_t*>(&data1_));
std::copy_n(bytes + DWORD, WORD, reinterpret_cast<uint8_t*>(&data2_));
std::copy_n(bytes + DWORD + WORD, WORD, reinterpret_cast<uint8_t*>(&data3_));
std::copy(bytes + QWORD, bytes + 2 * QWORD, data4_.begin());
}

Expand Down
2 changes: 1 addition & 1 deletion src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ void append(Blob& blob, const byte* buf, size_t len) {
blob.reserve(size + 65536);
}
blob.resize(size + len);
std::memcpy(&blob[size], buf, len);
std::copy_n(buf, len, &blob[size]);
}
} // append

Expand Down
2 changes: 1 addition & 1 deletion src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
while (count < length && !bWroteColor) {
Internal::enforce(boxHSize <= length - count, ErrorCode::kerCorruptedMetadata);
Internal::Jp2BoxHeader subBox;
memcpy(&subBox, boxBuf.c_data(count), boxHSize);
std::copy_n(boxBuf.c_data(count), boxHSize, reinterpret_cast<byte*>(&subBox));
Internal::Jp2BoxHeader newBox = subBox;

if (count < length) {
Expand Down
6 changes: 3 additions & 3 deletions src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
if (exifSize > 0xffff - 8)
throw Error(ErrorCode::kerTooLargeJpegSegment, "Exif");
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(exifSize + 8), bigEndian);
std::memcpy(tmpBuf.data() + 4, exifId_, 6);
std::copy_n(exifId_, 6, tmpBuf.data() + 4);
if (outIo.write(tmpBuf.data(), 10) != 10)
throw Error(ErrorCode::kerImageWriteFailed);

Expand All @@ -759,7 +759,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
if (xmpPacket_.size() > 0xffff - 31)
throw Error(ErrorCode::kerTooLargeJpegSegment, "XMP");
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(xmpPacket_.size() + 31), bigEndian);
std::memcpy(tmpBuf.data() + 4, xmpId_, 29);
std::copy_n(xmpId_, 29, tmpBuf.data() + 4);
if (outIo.write(tmpBuf.data(), 33) != 33)
throw Error(ErrorCode::kerImageWriteFailed);

Expand Down Expand Up @@ -835,7 +835,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
tmpBuf[0] = 0xff;
tmpBuf[1] = app13_;
us2Data(tmpBuf.data() + 2, static_cast<uint16_t>(chunkSize + 16), bigEndian);
std::memcpy(tmpBuf.data() + 4, Photoshop::ps3Id_, 14);
std::copy_n(Photoshop::ps3Id_, 14, tmpBuf.data() + 4);
if (outIo.write(tmpBuf.data(), 18) != 18)
throw Error(ErrorCode::kerImageWriteFailed);
if (outIo.error())
Expand Down
2 changes: 1 addition & 1 deletion src/pngimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ void PngImage::doWriteMetadata(BasicIo& outIo) {
throw Error(ErrorCode::kerInputDataReadFailed);

char szChunk[5];
memcpy(szChunk, cheaderBuf.c_data(4), 4);
std::copy_n(cheaderBuf.c_data(4), 4, szChunk);
szChunk[4] = 0;

if (!strcmp(szChunk, "IEND")) {
Expand Down
2 changes: 1 addition & 1 deletion src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ bool TiffBinaryArray::updOrigDataBuf(const byte* pData, size_t size) {
return false;
if (origData_ == pData)
return true;
memcpy(origData_, pData, origSize_);
std::copy_n(pData, origSize_, origData_);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ void TiffEncoder::encodeDataEntry(TiffDataEntry* object, const Exifdatum* datum)
#endif
DataBuf buf = object->pValue()->dataArea();
if (!buf.empty()) {
memcpy(object->pDataArea_, buf.c_data(), buf.size());
std::copy_n(buf.c_data(), buf.size(), object->pDataArea_);
if (object->sizeDataArea_ > buf.size()) {
memset(object->pDataArea_ + buf.size(), 0x0, object->sizeDataArea_ - buf.size());
}
Expand Down
4 changes: 2 additions & 2 deletions src/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ size_t DateValue::copy(byte* buf, ByteOrder /*byteOrder*/) const {
// sprintf wants to add the null terminator, so use oversized buffer
char temp[9];
auto wrote = static_cast<size_t>(snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day));
std::memcpy(buf, temp, wrote);
std::copy_n(temp, wrote, buf);
return wrote;
}

Expand Down Expand Up @@ -929,7 +929,7 @@ size_t TimeValue::copy(byte* buf, ByteOrder /*byteOrder*/) const {
plusMinus, abs(time_.tzHour), abs(time_.tzMinute)));

Internal::enforce(wrote == 11, Exiv2::ErrorCode::kerUnsupportedTimeFormat);
std::memcpy(buf, temp, wrote);
std::copy_n(temp, wrote, buf);
return wrote;
}

Expand Down

0 comments on commit d0833b5

Please sign in to comment.