mirror of https://github.com/minetest/minetest.git
Fix aliasing violation when reading primitives
This commit is contained in:
parent
6708ae051a
commit
d9cc838a0c
|
@ -153,7 +153,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd 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 .
|
cmake --build .
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <tiny_gltf.h>
|
#include <tiny_gltf.h>
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -76,7 +77,9 @@ static T readPrimitive(const BufferOffset& readFrom)
|
||||||
for (std::size_t i = 0; i < sizeof(T); ++i) {
|
for (std::size_t i = 0; i < sizeof(T); ++i) {
|
||||||
d[i] = readFrom.at(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)
|
static core::vector2df readVec2DF(const BufferOffset& readFrom)
|
||||||
|
|
Loading…
Reference in New Issue