Skip to content

Commit

Permalink
fix: remove use of reinterpret cast
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Oct 17, 2024
1 parent c4fde62 commit afa875b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/io/fileloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ class PropStream {
return false;
}

std::span<const unsigned char> sourceSpan(reinterpret_cast<const unsigned char*>(p), sizeof(T));
std::array<unsigned char, sizeof(T)> tempBuffer;
std::ranges::copy(sourceSpan, tempBuffer.begin());
std::span<const char> charSpan { p, sizeof(T) };
auto byteSpan = std::as_bytes(charSpan);

std::array<std::byte, sizeof(T)> tempBuffer;
std::ranges::copy(byteSpan, tempBuffer.begin());

ret = std::bit_cast<T>(tempBuffer);

p += sizeof(T);
Expand All @@ -93,10 +96,11 @@ class PropStream {
return false;
}

std::vector<unsigned char> tempBuffer(strLen);
std::span<const unsigned char> sourceSpan(reinterpret_cast<const unsigned char*>(p), strLen);
std::vector<char> tempBuffer(strLen);
std::span<const char> sourceSpan(p, strLen);
std::ranges::copy(sourceSpan, tempBuffer.begin());
ret.assign(reinterpret_cast<const char*>(tempBuffer.data()), strLen);

ret.assign(tempBuffer.begin(), tempBuffer.end());

p += strLen;

Expand Down

0 comments on commit afa875b

Please sign in to comment.