Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace reinterpret_cast with memcpy #2896

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/asfvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const {
}

AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
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::memcpy(&data1_, bytes, DWORD);
std::memcpy(&data2_, bytes + DWORD, WORD);
std::memcpy(&data3_, bytes + DWORD + WORD, WORD);
std::copy(bytes + QWORD, bytes + 2 * QWORD, data4_.begin());
if (isBigEndianPlatform()) {
data1_ = byteSwap(data1_, true);
Expand Down
2 changes: 1 addition & 1 deletion src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
return error(errors, "no such host: %s", gai_strerror(res));
}

serv_addr = *reinterpret_cast<sockaddr_in*>(result->ai_addr);
std::memcpy(&serv_addr, result->ai_addr, serv_len);

freeaddrinfo(result);
}
Expand Down
12 changes: 1 addition & 11 deletions src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,6 @@ void Jp2Image::writeMetadata() {

} // Jp2Image::writeMetadata

#ifdef __clang__
// ignore cast align errors. dataBuf.pData_ is allocated by malloc() and 4 (or 8 byte aligned).
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcast-align"
#endif

void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
DataBuf output(boxBuf.size() + iccProfile_.size() + 100); // allocate sufficient space
size_t outlen = boxHSize; // now many bytes have we written to output?
Expand All @@ -601,7 +595,7 @@ void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
while (count < length && !bWroteColor) {
Internal::enforce(boxHSize <= length - count, ErrorCode::kerCorruptedMetadata);
Internal::Jp2BoxHeader subBox;
std::copy_n(boxBuf.c_data(count), boxHSize, reinterpret_cast<byte*>(&subBox));
std::memcpy(&subBox, boxBuf.c_data(count), boxHSize);
Internal::Jp2BoxHeader newBox = subBox;

if (count < length) {
Expand Down Expand Up @@ -659,10 +653,6 @@ void Jp2Image::encodeJp2Header(const DataBuf& boxBuf, DataBuf& outBuf) {
ul2Data(outBuf.data(4), kJp2BoxTypeHeader, bigEndian);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif

void Jp2Image::doWriteMetadata(BasicIo& outIo) {
if (!io_->isopen())
throw Error(ErrorCode::kerInputDataReadFailed);
Expand Down
2 changes: 1 addition & 1 deletion src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ uint32_t TiffEncoder::updateDirEntry(byte* buf, ByteOrder byteOrder, TiffCompone
#endif
memset(buf + 8, 0x0, 4);
if (pTiffEntry->size() > 0) {
memmove(buf + 8, pTiffEntry->pData(), pTiffEntry->size());
std::copy_n(pTiffEntry->pData(), pTiffEntry->size(), buf + 8);
memset(const_cast<byte*>(pTiffEntry->pData()), 0x0, pTiffEntry->size());
}
}
Expand Down