From 0da8b29a8830b06062420dddcc2fb3eabb4657d4 Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 19 Mar 2024 22:14:53 +0100 Subject: [PATCH] Remove static modifier from local variables used to store temporary loading results They make the code thread unsafe because different threads will use the same memory to write and read using different instances of the loaded objects. --- components/esm4/loadcont.cpp | 2 +- components/esm4/loadcrea.cpp | 2 +- components/esm4/loadinfo.cpp | 2 +- components/esm4/loadlvlc.cpp | 2 +- components/esm4/loadlvli.cpp | 2 +- components/esm4/loadlvln.cpp | 2 +- components/esm4/loadnpc.cpp | 2 +- components/esm4/loadpack.cpp | 2 +- components/esm4/loadpgrd.cpp | 4 ++-- components/esm4/loadroad.cpp | 4 ++-- components/esm4/loadscpt.cpp | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/components/esm4/loadcont.cpp b/components/esm4/loadcont.cpp index d650678093..7c90472d29 100644 --- a/components/esm4/loadcont.cpp +++ b/components/esm4/loadcont.cpp @@ -53,7 +53,7 @@ void ESM4::Container::load(ESM4::Reader& reader) break; case ESM4::SUB_CNTO: { - static InventoryItem inv; // FIXME: use unique_ptr here? + InventoryItem inv; // FIXME: use unique_ptr here? reader.get(inv); reader.adjustFormId(inv.item); mInventory.push_back(inv); diff --git a/components/esm4/loadcrea.cpp b/components/esm4/loadcrea.cpp index 0c07eb92e3..cb587b091d 100644 --- a/components/esm4/loadcrea.cpp +++ b/components/esm4/loadcrea.cpp @@ -56,7 +56,7 @@ void ESM4::Creature::load(ESM4::Reader& reader) break; case ESM4::SUB_CNTO: { - static InventoryItem inv; // FIXME: use unique_ptr here? + InventoryItem inv; // FIXME: use unique_ptr here? reader.get(inv); reader.adjustFormId(inv.item); mInventory.push_back(inv); diff --git a/components/esm4/loadinfo.cpp b/components/esm4/loadinfo.cpp index 1b001c1665..1acc419ada 100644 --- a/components/esm4/loadinfo.cpp +++ b/components/esm4/loadinfo.cpp @@ -41,7 +41,7 @@ void ESM4::DialogInfo::load(ESM4::Reader& reader) mEditorId = ESM::RefId(mId).serializeText(); // FIXME: quick workaround to use existing code - static ScriptLocalVariableData localVar; + ScriptLocalVariableData localVar; bool ignore = false; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadlvlc.cpp b/components/esm4/loadlvlc.cpp index b1a0a0f241..8f045b6038 100644 --- a/components/esm4/loadlvlc.cpp +++ b/components/esm4/loadlvlc.cpp @@ -58,7 +58,7 @@ void ESM4::LevelledCreature::load(ESM4::Reader& reader) break; case ESM4::SUB_LVLO: { - static LVLO lvlo; + LVLO lvlo; if (subHdr.dataSize != 12) { if (subHdr.dataSize == 8) diff --git a/components/esm4/loadlvli.cpp b/components/esm4/loadlvli.cpp index cab8db4a21..6253db5272 100644 --- a/components/esm4/loadlvli.cpp +++ b/components/esm4/loadlvli.cpp @@ -56,7 +56,7 @@ void ESM4::LevelledItem::load(ESM4::Reader& reader) break; case ESM4::SUB_LVLO: { - static LVLO lvlo; + LVLO lvlo; if (subHdr.dataSize != 12) { if (subHdr.dataSize == 8) diff --git a/components/esm4/loadlvln.cpp b/components/esm4/loadlvln.cpp index febdcbeca9..3dff37614d 100644 --- a/components/esm4/loadlvln.cpp +++ b/components/esm4/loadlvln.cpp @@ -59,7 +59,7 @@ void ESM4::LevelledNpc::load(ESM4::Reader& reader) break; case ESM4::SUB_LVLO: { - static LVLO lvlo; + LVLO lvlo; if (subHdr.dataSize != 12) { if (subHdr.dataSize == 8) diff --git a/components/esm4/loadnpc.cpp b/components/esm4/loadnpc.cpp index 885263d67b..7c91da747e 100644 --- a/components/esm4/loadnpc.cpp +++ b/components/esm4/loadnpc.cpp @@ -59,7 +59,7 @@ void ESM4::Npc::load(ESM4::Reader& reader) break; case ESM4::SUB_CNTO: { - static InventoryItem inv; // FIXME: use unique_ptr here? + InventoryItem inv; // FIXME: use unique_ptr here? reader.get(inv); reader.adjustFormId(inv.item); mInventory.push_back(inv); diff --git a/components/esm4/loadpack.cpp b/components/esm4/loadpack.cpp index ab75598121..34ef000934 100644 --- a/components/esm4/loadpack.cpp +++ b/components/esm4/loadpack.cpp @@ -103,7 +103,7 @@ void ESM4::AIPackage::load(ESM4::Reader& reader) break; } - static CTDA condition; + CTDA condition; reader.get(condition); // FIXME: how to "unadjust" if not FormId? // adjustFormId(condition.param1); diff --git a/components/esm4/loadpgrd.cpp b/components/esm4/loadpgrd.cpp index 12cbf6f28b..d88cf41e8a 100644 --- a/components/esm4/loadpgrd.cpp +++ b/components/esm4/loadpgrd.cpp @@ -68,7 +68,7 @@ void ESM4::Pathgrid::load(ESM4::Reader& reader) } case ESM4::SUB_PGRR: { - static PGRR link; + PGRR link; for (std::size_t i = 0; i < std::size_t(mData); ++i) // keep gcc quiet { @@ -105,7 +105,7 @@ void ESM4::Pathgrid::load(ESM4::Reader& reader) } case ESM4::SUB_PGRL: { - static PGRL objLink; + PGRL objLink; reader.getFormId(objLink.object); // object linkedNode std::size_t numNodes = (subHdr.dataSize - sizeof(int32_t)) / sizeof(int32_t); diff --git a/components/esm4/loadroad.cpp b/components/esm4/loadroad.cpp index 8a33ab1c1d..2cf5b2ed90 100644 --- a/components/esm4/loadroad.cpp +++ b/components/esm4/loadroad.cpp @@ -59,8 +59,8 @@ void ESM4::Road::load(ESM4::Reader& reader) } case ESM4::SUB_PGRR: { - static PGRR link; - static RDRP linkPt; + PGRR link; + RDRP linkPt; for (std::size_t i = 0; i < mNodes.size(); ++i) { diff --git a/components/esm4/loadscpt.cpp b/components/esm4/loadscpt.cpp index b4071ed21d..841bfbc839 100644 --- a/components/esm4/loadscpt.cpp +++ b/components/esm4/loadscpt.cpp @@ -36,7 +36,7 @@ void ESM4::Script::load(ESM4::Reader& reader) mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; - static ScriptLocalVariableData localVar; + ScriptLocalVariableData localVar; while (reader.getSubRecordHeader()) {