From e56a372871a4a8e7b83d375ee9183829e5d81b38 Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Wed, 22 Jul 2026 11:10:55 -0300 Subject: [PATCH] give the XML tag map and the writer buffer a name Both of these bound a non-const reference to a temporary, which MSVC accepts and clang does not, and which leaves the reference dangling once the full expression ends. PropertyContainer::initFromXMLFile and writeToXMLFile take their tag map by non-const reference because the accessors on it insert default tag names as they are asked for, so it cannot be const and it cannot be a temporary. All eight call sites passed a freshly built one; they now declare it. Each keeps its own object, so a map filled in by one call cannot leak into the next, the same as when each call built its own temporary. XMLWriter::writeToFile bound std::string& to what stringstream::str() returns by value. Declared as a value it is initialised straight from the return with no copy, and const because only c_str() and length() are asked of it. Verification: grep -rn 'PropertyContainer::TagMap()' . # nothing ninja -C build parse # no i18n or XMLWriter sites remain ninja -C build -k 0 # Release, four applications, green ninja -C build-debug -k 0 # Debug, four applications, green Co-Authored-By: Claude Opus 4.8 --- Utils/XMLWriter.cpp | 2 +- i18n/ExportStrings.cpp | 18 ++++++++++++------ i18n/LocalizedStrings.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Utils/XMLWriter.cpp b/Utils/XMLWriter.cpp index 8b1c407a7..8e5ed8857 100644 --- a/Utils/XMLWriter.cpp +++ b/Utils/XMLWriter.cpp @@ -75,7 +75,7 @@ bool XMLWriter::writeToFile(vfs::tWritableFile* pFile) try { vfs::COpenWriteFile file(pFile); - std::string &str = m_ssBuffer.str(); + const std::string str = m_ssBuffer.str(); pFile->write(str.c_str(), str.length() * sizeof(std::string::value_type)); return true; } diff --git a/i18n/ExportStrings.cpp b/i18n/ExportStrings.cpp index 6109ebe07..daedb0458 100644 --- a/i18n/ExportStrings.cpp +++ b/i18n/ExportStrings.cpp @@ -524,7 +524,8 @@ void ExportMercBio() Translate(pAddInfo, SIZE_MERC_ADDITIONAL_INFO, g_lang); props.setStringProperty(L"Add", vfs::toString(i), pAddInfo); } - props.writeToXMLFile(L"Localization/AimBiographies.xml", vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + props.writeToXMLFile(L"Localization/AimBiographies.xml", tags); } void ExportAIMHistory() @@ -544,7 +545,8 @@ void ExportAIMHistory() Translate(pHistLine, AIM_HISTORY_LINE_SIZE, g_lang); props.setStringProperty(L"Line", vfs::toString(i), pHistLine); } - props.writeToXMLFile(L"Localization/AimHistory.xml", vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + props.writeToXMLFile(L"Localization/AimHistory.xml", tags); } @@ -565,7 +567,8 @@ void ExportAIMPolicy() Translate(pPolLine, AIM_HISTORY_LINE_SIZE, g_lang); props.setStringProperty(L"Line", vfs::toString(i), pPolLine); } - props.writeToXMLFile(L"Localization/AimPolicy.xml", vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + props.writeToXMLFile(L"Localization/AimPolicy.xml", tags); } void ExportAlumniName() @@ -585,7 +588,8 @@ void ExportAlumniName() Translate(pAlumniName, AIM_ALUMNI_NAME_SIZE, g_lang); props.setStringProperty(L"Line", vfs::toString(i), pAlumniName); } - props.writeToXMLFile(L"Localization/AlumniName.xml", vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + props.writeToXMLFile(L"Localization/AlumniName.xml", tags); } void ExportDialogues() @@ -621,7 +625,8 @@ void ExportDialogues() } vfs::Path x(L"Localization/Dialogue"); x += vfs::Path(file.getName().c_wcs() + L".xml"); - props.writeToXMLFile(x, vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + props.writeToXMLFile(x, tags); } } @@ -668,7 +673,8 @@ void ExportNPCDialogues() } vfs::Path x(L"Localization/NpcDialogue"); x += vfs::Path(file.getName().c_wcs() + L".xml"); - props.writeToXMLFile(x, vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + props.writeToXMLFile(x, tags); } } } // namespace diff --git a/i18n/LocalizedStrings.cpp b/i18n/LocalizedStrings.cpp index 62153401f..fb9f6940b 100644 --- a/i18n/LocalizedStrings.cpp +++ b/i18n/LocalizedStrings.cpp @@ -86,13 +86,15 @@ void Loc::Init(Topic t, vfs::String const& section) _PropState& state = _topicFiles[t][L"_ALL"]; if(!state.filename.empty() && !state.loaded) { - _localizedStrings[t].initFromXMLFile(state.filename, vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + _localizedStrings[t].initFromXMLFile(state.filename, tags); state.loaded = true; } state = _topicFiles[t][section]; if(!state.filename.empty() && !state.loaded) { - _localizedStrings[t].initFromXMLFile(state.filename, vfs::PropertyContainer::TagMap()); + vfs::PropertyContainer::TagMap tags; + _localizedStrings[t].initFromXMLFile(state.filename, tags); state.loaded = true; } }