From 88fe328de1db43fbe815394f6fc3c8855a32b1b0 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 18 Aug 2023 13:13:00 +0400 Subject: [PATCH] Add a safeguard to do not use uninitialized value --- apps/openmw/mwworld/store.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index cf407f9291..3d88851672 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -355,18 +355,26 @@ namespace MWWorld template RecordId TypedDynamicStore::read(ESM::ESMReader& reader, bool overrideOnly) { - T record; - bool isDeleted = false; if constexpr (!ESM::isESM4Rec(T::sRecordId)) { + T record; + bool isDeleted = false; record.load(reader, isDeleted); - } - insert(record, overrideOnly); - if constexpr (std::is_same_v) - return RecordId(record.mId, isDeleted); + insert(record, overrideOnly); + + if constexpr (std::is_same_v) + return RecordId(record.mId, isDeleted); + else + return RecordId(); + } else - return RecordId(); + { + std::stringstream msg; + msg << "Can not load record of type ESM::REC_" << getRecNameString(T::sRecordId).toStringView() + << ": ESM::ESMReader can load only ESM3 records."; + throw std::runtime_error(msg.str()); + } } // LandTexture