mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-17 10:21:11 +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:
commit
e5dc8e1ec9
@ -163,7 +163,8 @@ namespace
|
|||||||
{
|
{
|
||||||
if (sizeof(TestStruct1) != binaryData.size())
|
if (sizeof(TestStruct1) != binaryData.size())
|
||||||
throw std::runtime_error("Incorrect binaryData.size() for TestStruct1: " + std::to_string(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.a = Misc::fromLittleEndian(t.a);
|
||||||
t.b = Misc::fromLittleEndian(t.b);
|
t.b = Misc::fromLittleEndian(t.b);
|
||||||
sol::stack::push<TestStruct1>(lua, t);
|
sol::stack::push<TestStruct1>(lua, t);
|
||||||
@ -173,7 +174,8 @@ namespace
|
|||||||
{
|
{
|
||||||
if (sizeof(TestStruct2) != binaryData.size())
|
if (sizeof(TestStruct2) != binaryData.size())
|
||||||
throw std::runtime_error("Incorrect binaryData.size() for TestStruct2: " + std::to_string(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.a = Misc::fromLittleEndian(t.a);
|
||||||
t.b = Misc::fromLittleEndian(t.b);
|
t.b = Misc::fromLittleEndian(t.b);
|
||||||
sol::stack::push<TestStruct2>(lua, t);
|
sol::stack::push<TestStruct2>(lua, t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user