From 003853d665d6a8fe5300085a33f10e61d66a6e18 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Fri, 3 Mar 2023 08:40:35 +0100 Subject: [PATCH] BACKENDS: DIALOGS: GTK: Set and restore locale when using GTK dialogs Gtk sets the locale when it's set up to make parts of the UI localized. We set it properly before displaying the dialog and reset to "C" afterwards to avoid portability issues in number parsing functions. Fixes #14196 Thanks to @rootfather and @elasota for the investigation. --- backends/dialogs/gtk/gtk-dialogs.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backends/dialogs/gtk/gtk-dialogs.cpp b/backends/dialogs/gtk/gtk-dialogs.cpp index 03f0d6c483d..8bbbb13c048 100644 --- a/backends/dialogs/gtk/gtk-dialogs.cpp +++ b/backends/dialogs/gtk/gtk-dialogs.cpp @@ -22,6 +22,7 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_FILE #define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h #define FORBIDDEN_SYMBOL_EXCEPTION_time_h +#define FORBIDDEN_SYMBOL_EXCEPTION_setlocale #include "common/scummsys.h" #if defined(POSIX) && defined(USE_SYSDIALOGS) && defined(USE_GTK) @@ -32,6 +33,7 @@ #include "common/events.h" #include "common/translation.h" +#include #include // TODO: Move this into the class? Probably possible, but I've been told that @@ -66,6 +68,10 @@ Common::DialogManager::DialogResult GtkDialogManager::showFileBrowser(const Comm if (isDirBrowser) { action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; } + + // Set locale to environment one to let user have its localized folders in the browser + setlocale(LC_ALL, ""); + #if GTK_CHECK_VERSION(3,20,0) GtkFileChooserNative *native = gtk_file_chooser_native_new(utf8Title.c_str(), NULL, action, utf8Choose.c_str(), utf8Cancel.c_str()); GtkFileChooser *chooser = GTK_FILE_CHOOSER(native); @@ -102,6 +108,11 @@ Common::DialogManager::DialogResult GtkDialogManager::showFileBrowser(const Comm _inDialog = FALSE; + // Restore default C locale to prevent issues with + // portability of sscanf(), atof(), etc. + // See bugs #6434 and #14196 + setlocale(LC_ALL, "C"); + #if GTK_CHECK_VERSION(3,20,0) g_object_unref(native); #else