aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/settings.cpp10
-rw-r--r--src/settings.h4
-rw-r--r--src/unittest/test_settings.cpp18
3 files changed, 16 insertions, 16 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 473a216bf..28b72c4e3 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -822,22 +822,22 @@ bool Settings::setDefault(const std::string &name, const std::string &value)
}
-bool Settings::setGroup(const std::string &name, Settings *group)
+bool Settings::setGroup(const std::string &name, const Settings &group)
{
// Settings must own the group pointer
// avoid double-free by copying the source
Settings *copy = new Settings();
- *copy = *group;
+ *copy = group;
return setEntry(name, &copy, true, false);
}
-bool Settings::setGroupDefault(const std::string &name, Settings *group)
+bool Settings::setGroupDefault(const std::string &name, const Settings &group)
{
// Settings must own the group pointer
// avoid double-free by copying the source
Settings *copy = new Settings();
- *copy = *group;
+ *copy = group;
return setEntry(name, &copy, true, true);
}
@@ -1060,7 +1060,7 @@ void Settings::overrideDefaults(Settings *other)
{
for (const auto &setting : other->m_settings) {
if (setting.second.is_group) {
- setGroupDefault(setting.first, setting.second.group);
+ setGroupDefault(setting.first, *setting.second.group);
continue;
}
const FlagDesc *flagdesc = getFlagDescFallback(setting.first);
diff --git a/src/settings.h b/src/settings.h
index 0c9a155db..ccc252049 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -192,8 +192,8 @@ public:
bool set_group, bool set_default);
bool set(const std::string &name, const std::string &value);
bool setDefault(const std::string &name, const std::string &value);
- bool setGroup(const std::string &name, Settings *group);
- bool setGroupDefault(const std::string &name, Settings *group);
+ bool setGroup(const std::string &name, const Settings &group);
+ bool setGroupDefault(const std::string &name, const Settings &group);
bool setBool(const std::string &name, bool value);
bool setS16(const std::string &name, s16 value);
bool setU16(const std::string &name, u16 value);
diff --git a/src/unittest/test_settings.cpp b/src/unittest/test_settings.cpp
index aa56f3e06..f91ba5b67 100644
--- a/src/unittest/test_settings.cpp
+++ b/src/unittest/test_settings.cpp
@@ -149,15 +149,15 @@ void TestSettings::testAllSettings()
UASSERT(group->getS16("a") == 5);
UASSERT(fabs(group->getFloat("bb") - 2.5) < 0.001);
- Settings *group3 = new Settings;
- group3->set("cat", "meow");
- group3->set("dog", "woof");
-
- Settings *group2 = new Settings;
- group2->setS16("num_apples", 4);
- group2->setS16("num_oranges", 53);
- group2->setGroup("animals", group3);
- group2->set("animals", "cute"); //destroys group 3
+ Settings group3;
+ group3.set("cat", "meow");
+ group3.set("dog", "woof");
+
+ Settings group2;
+ group2.setS16("num_apples", 4);
+ group2.setS16("num_oranges", 53);
+ group2.setGroup("animals", group3);
+ group2.set("animals", "cute"); //destroys group 3
s.setGroup("groupy_thing", group2);
// Test set failure conditions