[vlmc-devel] commit: SettingsManager: Don't crash when loading a non existant setting. ( =?UTF-8?Q?Hugo=20Beauz=C3=A9e=2DLuyssen?==?UTF-8?Q?=20?=)

git at videolan.org git at videolan.org
Sat Nov 27 15:34:06 CET 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sat Nov 27 14:54:29 2010 +0100| [e17a589849d6fea37163ccb8dbb02bd1361aa77f] | committer: Hugo Beauzée-Luyssen 

SettingsManager: Don't crash when loading a non existant setting.

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=e17a589849d6fea37163ccb8dbb02bd1361aa77f
---

 src/Settings/SettingsManager.cpp |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/src/Settings/SettingsManager.cpp b/src/Settings/SettingsManager.cpp
index 0ace1d0..3ed36eb 100644
--- a/src/Settings/SettingsManager.cpp
+++ b/src/Settings/SettingsManager.cpp
@@ -47,6 +47,21 @@ getPair( SettingsManager::SettingList &list, const QString &key )
     return end;
 }
 
+static bool
+contains( const SettingsManager::SettingList &list, const QString &key )
+{
+    SettingsManager::SettingList::const_iterator        it = list.constBegin();
+    SettingsManager::SettingList::const_iterator        end = list.constEnd();
+
+    while ( it != end )
+    {
+        if ( *it == key )
+            return true;
+        ++it;
+    }
+    return false;
+}
+
 void
 SettingsManager::setValue( const QString &key,
                            const QVariant &value,
@@ -221,7 +236,12 @@ SettingsManager::load( const QDomElement &root )
         if ( key.isEmpty() == true || value.isEmpty() == true )
             qWarning() << "Invalid setting node.";
         else
-            setValue( key, value, SettingsManager::Project );
+        {
+            if ( contains( m_xmlSettings, key ) == true )
+                setValue( key, value, SettingsManager::Project );
+            else
+                qWarning() << "Invalid setting node in project file:" << key;
+        }
         s = s.nextSiblingElement();
     }
     return true;



More information about the Vlmc-devel mailing list