Merge branch 'fix_ub' into 'master'

Fix UB: reference binding to misaligned address in Lua tests

See merge request OpenMW/openmw!1025
dont-compose-content
jvoisin 4 years ago
commit e5dc8e1ec9

@ -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);

Loading…
Cancel
Save