From 4fb01dd766c824529dad4bd1ca64a981e137d476 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 25 Nov 2017 09:22:19 +0100 Subject: 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 --- desktop-widgets/preferences/preferencesdialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 6f5f4b9fa..50a0049ac 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -109,7 +109,7 @@ void PreferencesDialog::refreshPages() curr->setParent(0); } - // Readd things. + // Read things Q_FOREACH(AbstractPreferencesWidget *page, pages) { QListWidgetItem *item = new QListWidgetItem(page->icon(), page->name()); pagesList->addItem(item); @@ -139,7 +139,7 @@ void PreferencesDialog::cancelRequested() void PreferencesDialog::defaultsRequested() { - prefs = default_prefs; + copy_prefs(&default_prefs, &prefs); Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->refreshSettings(); } -- cgit v1.2.3-70-g09d2