Merge pull request #1777 from Azaezel/alpha41/tamlWriteRight
Some checks failed
MacOSX Build / macOS ARM Clang Ninja (push) Has been cancelled
Linux Build / Ubuntu GCC Latest (push) Has been cancelled
Linux Build / Ubuntu GCC 13 (push) Has been cancelled
MacOSX Build / macOS ARM Xcode (push) Has been cancelled
Windows Build / Windows MSVC Ninja (push) Has been cancelled
Windows Build / Windows MSVC Visual Studio 2022 (push) Has been cancelled
Windows Build / Windows MSVC Visual Studio 2026 (push) Has been cancelled

harden Taml::write and Taml::compileCustomState
This commit is contained in:
Areloch 2026-06-22 02:54:33 -05:00 committed by GitHub
commit e9a517a9f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View file

@ -151,7 +151,8 @@ Taml::Taml() :
mAutoFormat(true), mAutoFormat(true),
mProgenitorUpdate(true), mProgenitorUpdate(true),
mAutoFormatBinaryExtension("baml"), mAutoFormatBinaryExtension("baml"),
mAutoFormatJSONExtension("json") mAutoFormatJSONExtension("json"),
mWriteLocked(false)
{ {
// Reset the file-path buffer. // Reset the file-path buffer.
mFilePathBuffer[0] = 0; mFilePathBuffer[0] = 0;
@ -215,6 +216,10 @@ bool Taml::write(SimObject* pSimObject, const char* pFilename)
AssertFatal(pSimObject != NULL, "Cannot write a NULL object."); AssertFatal(pSimObject != NULL, "Cannot write a NULL object.");
AssertFatal(pFilename != NULL, "Cannot write to a NULL filename."); AssertFatal(pFilename != NULL, "Cannot write to a NULL filename.");
if (mWriteLocked)
return false;
mWriteLocked = true;
// Expand the file-name into the file-path buffer unless we're a secure VFS // Expand the file-name into the file-path buffer unless we're a secure VFS
#ifndef TORQUE_SECURE_VFS #ifndef TORQUE_SECURE_VFS
Con::expandToolScriptFilename(mFilePathBuffer, sizeof(mFilePathBuffer), pFilename); Con::expandToolScriptFilename(mFilePathBuffer, sizeof(mFilePathBuffer), pFilename);
@ -230,6 +235,7 @@ bool Taml::write(SimObject* pSimObject, const char* pFilename)
{ {
// No, so warn. // No, so warn.
Con::warnf("Taml::writeFile() - Could not open filename '%s' for write.", mFilePathBuffer); Con::warnf("Taml::writeFile() - Could not open filename '%s' for write.", mFilePathBuffer);
mWriteLocked = false;
return false; return false;
} }
@ -247,7 +253,7 @@ bool Taml::write(SimObject* pSimObject, const char* pFilename)
// Reset the compilation. // Reset the compilation.
resetCompilation(); resetCompilation();
mWriteLocked = false;
return status; return status;
} }
@ -488,6 +494,10 @@ void Taml::resetCompilation(void)
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(Taml_ResetCompilation); PROFILE_SCOPE(Taml_ResetCompilation);
// make sure we don't reset while writing, as this can cause a crash
if (mWriteLocked)
return;
// Clear compiled nodes. // Clear compiled nodes.
for (typeNodeVector::iterator itr = mCompiledNodes.begin(); itr != mCompiledNodes.end(); ++itr) for (typeNodeVector::iterator itr = mCompiledNodes.begin(); itr != mCompiledNodes.end(); ++itr)
{ {
@ -926,8 +936,12 @@ void Taml::compileCustomState(TamlWriteNode* pTamlWriteNode)
tamlCustomWrite(pTamlWriteNode->mpTamlCallbacks, customNodes); tamlCustomWrite(pTamlWriteNode->mpTamlCallbacks, customNodes);
} }
// make sure we have compiled nodes to work with
if (mCompiledNodes.size() == 0)
return;
// Fetch custom nodes. // Fetch custom nodes.
const TamlCustomNodeVector& nodes = customNodes.getNodes(); TamlCustomNodeVector nodes = customNodes.getNodes();
// Finish if no custom nodes to process. // Finish if no custom nodes to process.
if (nodes.size() == 0) if (nodes.size() == 0)

View file

@ -99,6 +99,7 @@ private:
bool mAutoFormat; bool mAutoFormat;
bool mWriteDefaults; bool mWriteDefaults;
bool mProgenitorUpdate; bool mProgenitorUpdate;
bool mWriteLocked;
char mFilePathBuffer[1024]; char mFilePathBuffer[1024];
private: private: