summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2017-11-25 09:22:19 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-11-25 07:41:09 -0800
commit4fb01dd766c824529dad4bd1ca64a981e137d476 (patch)
treefe6b8e0fcea6045c048fdf8d6449af7f1acf8a4e /core
parentcc5a56b2751de2387572eec25fde75db7b89fb6a (diff)
downloadsubsurface-4fb01dd766c824529dad4bd1ca64a981e137d476.tar.gz
Fix ownership issues in preferences code
Each preferences object owns its string members. In three cases, pointers were copied instead of strings, leading to (in the best case) dangling pointers if the user edited values: 1) In the GET_TXT macro in core/prefs-macros.h 2) In the PreferencesDialog::defaultsRequested() method 3) In main() of the mobile version This patch fixes these issues, by using copy_string() or copy_prefs() as appropriate. The only reason that the old code didn't crash regularly is that the default_prefs object was only used at startup and defaultsRequested() is (at the moment?) dead code. This patch also aligns the backslashes in core/pref.h and fixes a typo. The declaration of copy_prefs() is moved to the core/prefs.h header. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/pref.h1
-rw-r--r--core/prefs-macros.h10
-rw-r--r--core/subsurfacestartup.h1
3 files changed, 6 insertions, 6 deletions
diff --git a/core/pref.h b/core/pref.h
index 198d4b9fe..d25115c8e 100644
--- a/core/pref.h
+++ b/core/pref.h
@@ -189,6 +189,7 @@ extern const char *system_default_directory(void);
extern const char *system_default_filename();
extern bool subsurface_ignore_font(const char *font);
extern void subsurface_OS_pref_setup();
+extern void copy_prefs(struct preferences *src, struct preferences *dest);
#ifdef __cplusplus
}
diff --git a/core/prefs-macros.h b/core/prefs-macros.h
index 6f1b665fd..15a9a9867 100644
--- a/core/prefs-macros.h
+++ b/core/prefs-macros.h
@@ -18,10 +18,10 @@
else \
prefs.units.field = default_prefs.units.field
-#define GET_UNIT_BOOL(name, field) \
+#define GET_UNIT_BOOL(name, field) \
v = s.value(QString(name)); \
if (v.isValid()) \
- prefs.units.field = v.toBool(); \
+ prefs.units.field = v.toBool(); \
else \
prefs.units.field = default_prefs.units.field
@@ -53,10 +53,10 @@
else \
prefs.field = default_prefs.field
-#define GET_INT_DEF(name, field, defval) \
+#define GET_INT_DEF(name, field, defval) \
v = s.value(QString(name)); \
if (v.isValid()) \
- prefs.field = v.toInt(); \
+ prefs.field = v.toInt(); \
else \
prefs.field = defval
@@ -65,7 +65,7 @@
if (v.isValid()) \
prefs.field = strdup(v.toString().toUtf8().constData()); \
else \
- prefs.field = default_prefs.field
+ prefs.field = copy_string(default_prefs.field)
#define SAVE_OR_REMOVE_SPECIAL(_setting, _default, _compare, _value) \
if (_compare != _default) \
diff --git a/core/subsurfacestartup.h b/core/subsurfacestartup.h
index b26c99025..40de09723 100644
--- a/core/subsurfacestartup.h
+++ b/core/subsurfacestartup.h
@@ -17,7 +17,6 @@ extern bool imported;
void setup_system_prefs(void);
void parse_argument(const char *arg);
void free_prefs(void);
-void copy_prefs(struct preferences *src, struct preferences *dest);
void print_files(void);
void print_version(void);