summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-06 10:15:38 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-06 10:19:43 +0100
commit9d8b0addf94c86f224093bb1ca66ebe18494ff7c (patch)
tree6d6b07d5dfabf73e3c58847af2b15b3754a9a357 /tests
parentc75ec7a04ab14c906c3e58febf142ffb8f73b8bc (diff)
downloadsubsurface-9d8b0addf94c86f224093bb1ca66ebe18494ff7c.tar.gz
Correctly copy preferences
When just assigning one structure to the other we copy the string pointers. If we then modify those strings in the copy, we happily free the strings of the original. And then resetting the preferences equally happily reused those strings, pointing to long since freed memory. I think what I did now is excessive for the current use case in that it copies a ton of strings that are unset in the default_prefs. But I figured this is a rarely used function and I might as well do it correctly. Also, once we implement multi user support with per user preferences we will be copying completely populated preferences around (at least that's my guess). Fixes #940 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/testgitstorage.cpp3
-rw-r--r--tests/testplan.cpp4
2 files changed, 4 insertions, 3 deletions
diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp
index 1b7c50fdb..ed9465386 100644
--- a/tests/testgitstorage.cpp
+++ b/tests/testgitstorage.cpp
@@ -5,6 +5,7 @@
#include "git2.h"
#include "prefs-macros.h"
#include "windowtitleupdate.h"
+#include "subsurfacestartup.h"
#include <QDir>
#include <QTextStream>
#include <QNetworkProxy>
@@ -17,7 +18,7 @@ extern "C" char *get_local_dir(const char *remote, const char *branch);
void TestGitStorage::testSetup()
{
// first, setup the preferences an proxy information
- prefs = default_prefs;
+ copy_prefs(&default_prefs, &prefs);
QCoreApplication::setOrganizationName("Subsurface");
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
QCoreApplication::setApplicationName("Subsurface");
diff --git a/tests/testplan.cpp b/tests/testplan.cpp
index 9818a8360..e73070439 100644
--- a/tests/testplan.cpp
+++ b/tests/testplan.cpp
@@ -14,7 +14,7 @@ extern pressure_t first_ceiling_pressure;
void setupPrefs()
{
- prefs = default_prefs;
+ copy_prefs(&default_prefs, &prefs);
prefs.ascrate50 = feet_to_mm(30) / 60;
prefs.ascrate75 = prefs.ascrate50;
prefs.ascratestops = prefs.ascrate50;
@@ -24,7 +24,7 @@ void setupPrefs()
void setupPrefsVpmb()
{
- prefs = default_prefs;
+ copy_prefs(&default_prefs, &prefs);
prefs.ascrate50 = 10000 / 60;
prefs.ascrate75 = prefs.ascrate50;
prefs.ascratestops = prefs.ascrate50;