1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-05 22:19:43 +00:00

Merge branch 'fix_ub' into 'master'

Fix UB: reference binding to misaligned address in Lua tests

See merge request OpenMW/openmw!1025
This commit is contained in:
jvoisin 2021-07-18 09:31:48 +00:00
commit e5dc8e1ec9

View file

@ -163,7 +163,8 @@ namespace
{
if (sizeof(TestStruct1) != binaryData.size())
throw std::runtime_error("Incorrect binaryData.size() for TestStruct1: " + std::to_string(binaryData.size()));
TestStruct1 t = *reinterpret_cast<const TestStruct1*>(binaryData.data());
TestStruct1 t;
std::memcpy(&t, binaryData.data(), sizeof(t));
t.a = Misc::fromLittleEndian(t.a);
t.b = Misc::fromLittleEndian(t.b);
sol::stack::push<TestStruct1>(lua, t);
@ -173,7 +174,8 @@ namespace
{
if (sizeof(TestStruct2) != binaryData.size())
throw std::runtime_error("Incorrect binaryData.size() for TestStruct2: " + std::to_string(binaryData.size()));
TestStruct2 t = *reinterpret_cast<const TestStruct2*>(binaryData.data());
TestStruct2 t;
std::memcpy(&t, binaryData.data(), sizeof(t));
t.a = Misc::fromLittleEndian(t.a);
t.b = Misc::fromLittleEndian(t.b);
sol::stack::push<TestStruct2>(lua, t);