From 04e026c53ff95cd260081fa747b6adc0aa805b9d Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 3 Jun 2023 20:28:25 +0200 Subject: [PATCH] getRecNameString now constexpr getTypeDescription uses a static constexpr variable so we don't return ref to temp memory. --- apps/openmw/mwworld/livecellref.hpp | 5 ++++- components/esm/defs.hpp | 11 +++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index dc38ff9830..8a3121e9c4 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -142,7 +142,10 @@ namespace MWWorld std::string_view getTypeDescription() const override { if constexpr (ESM::isESM4Rec(X::sRecordId)) - return ESM::getRecNameString(X::sRecordId).toStringView(); + { + static constexpr ESM::FixedString<6> name = ESM::getRecNameString(X::sRecordId); + return name.toStringView(); + } else return X::getRecordType(); } diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index 265e355871..65bda19597 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -332,17 +332,16 @@ namespace ESM return RecName & sEsm4RecnameFlag; } - inline FixedString<6> getRecNameString(ESM::RecNameInts recName) + constexpr inline FixedString<6> getRecNameString(ESM::RecNameInts recName) { ESM::FixedString<6> name; - name.assign(""); + name.mData[5] = '\0'; + ESM::NAME fourCCName(recName & ~ESM::sEsm4RecnameFlag); for (int i = 0; i < 4; i++) name.mData[i] = fourCCName.mData[i]; - if (ESM::isESM4Rec(recName)) - { - name.mData[4] = '4'; - } + + name.mData[4] = ESM::isESM4Rec(recName) ? '4' : '\0'; return name; }