Fix aliasing violation when reading primitives

This commit is contained in:
Josiah VanderZee 2022-11-13 07:55:30 -06:00 committed by JosiahWI
parent ad9fda174f
commit d4eea38a65
No known key found for this signature in database
GPG Key ID: C7BB8573A4ABC4B9
2 changed files with 5 additions and 2 deletions

View File

@ -111,7 +111,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)