Fix aliasing violation when reading primitives

This commit is contained in:
Josiah VanderZee 2022-11-13 07:55:30 -06:00
parent 3dc24abdb3
commit 47a195b4de
2 changed files with 5 additions and 2 deletions

View File

@ -153,7 +153,7 @@ jobs:
run: |
mkdir build
cd build
cmake -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/g++-5 -DCMAKE_BUILD_TYPE=Release ..
cmake -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/g++-5 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Werror" ..
cmake --build .
cd ..

View File

@ -15,6 +15,7 @@
#include <tiny_gltf.h>
#include <cstddef>
#include <cstring>
#include <memory>
#include <string>
@ -76,7 +77,9 @@ static T readPrimitive(const BufferOffset& readFrom)
for (std::size_t i = 0; i < sizeof(T); ++i) {
d[i] = readFrom.at(i);
}
return *reinterpret_cast<T*>(d);
T dest;
std::memcpy(&dest, d, sizeof(dest));
return dest;
}
static core::vector2df readVec2DF(const BufferOffset& readFrom)