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>
This commit is contained in:
Berthold Stoeger 2017-11-25 09:22:19 +01:00 committed by Dirk Hohndel
parent cc5a56b275
commit 4fb01dd766
5 changed files with 9 additions and 9 deletions

View file

@ -41,7 +41,7 @@ int main(int argc, char **argv)
setup_system_prefs();
if (uiLanguage(0).contains("-US"))
default_prefs.units = IMPERIAL_units;
prefs = default_prefs;
copy_prefs(&default_prefs, &prefs);
fill_profile_color();
fill_computer_list();