From bc84f63223dcdfb9a7b5a4ac5e37f7aad6430ce4 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 18 Jan 2024 20:07:26 -0800 Subject: [PATCH] replace copy_n + reinterpret_cast with memcpy These usages are not problematic, but they would be if alignment does not match. Also less verbose. Signed-off-by: Rosen Penev --- src/asfvideo.cpp | 6 +++--- src/jp2image.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/asfvideo.cpp b/src/asfvideo.cpp index 15d0edc3..f52d39eb 100644 --- a/src/asfvideo.cpp +++ b/src/asfvideo.cpp @@ -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(&data1_)); - std::copy_n(bytes + DWORD, WORD, reinterpret_cast(&data2_)); - std::copy_n(bytes + DWORD + WORD, WORD, reinterpret_cast(&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); diff --git a/src/jp2image.cpp b/src/jp2image.cpp index c61cc355..153bc725 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -601,7 +601,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(&subBox)); + std::memcpy(&subBox, boxBuf.c_data(count), boxHSize); Internal::Jp2BoxHeader newBox = subBox; if (count < length) {