From 4d4bf579b2ada3607818c90c292f39c0fee7fae3 Mon Sep 17 00:00:00 2001 From: elexis Date: Mon, 16 Sep 2019 16:13:25 +0000 Subject: [PATCH] Report and tolerate XML GUI object setting errors when parsing XML attribute strings as values for settings that don't exist on the GUI object. Following e326ebae46, 80b1876b77, d6db5a466d, ... the XML errors were silently ignored. Following 1a49ccb294 it led to a crash (m_Setting access for an item that does not exist). Differential Revision: https://code.wildfiregames.com/D2297 Tested on: clang 8.0.1, Jenkins This was SVN commit r22911. --- source/gui/CGUI.cpp | 6 +----- source/gui/IGUIObject.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index d38ae7ff80..199b052b50 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -715,11 +715,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec if (attr.Name == attr_z) ManuallySetZ = true; - const CStr settingName = pFile->GetAttributeString(attr.Name); - if (object->SettingExists(settingName)) - object->SetSettingFromString(settingName, attr.Value.FromUTF8(), false); - else - LOGERROR("GUI: (object: %s) Can't set \"%s\" to \"%s\"", object->GetPresentableName(), settingName, attr.Value); + object->SetSettingFromString(pFile->GetAttributeString(attr.Name), attr.Value.FromUTF8(), false); } // Check if name isn't set, generate an internal name in that case. diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp index c0ef85c024..b7442b8c18 100644 --- a/source/gui/IGUIObject.cpp +++ b/source/gui/IGUIObject.cpp @@ -148,7 +148,13 @@ const T& IGUIObject::GetSetting(const CStr& Setting) const bool IGUIObject::SetSettingFromString(const CStr& Setting, const CStrW& Value, const bool SendMessage) { - return m_Settings[Setting]->FromString(Value, SendMessage); + const std::map::iterator it = m_Settings.find(Setting); + if (it == m_Settings.end()) + { + LOGERROR("GUI object '%s' has no property called '%s', can't set parse and set value '%s'", GetPresentableName().c_str(), Setting.c_str(), Value.ToUTF8().c_str()); + return false; + } + return it->second->FromString(Value, SendMessage); } template