From: James Turner Date: Tue, 2 Feb 2016 20:44:46 +0000 (+0000) Subject: Defensive handling of locales. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c72309360ecddb245f8c1717eb3df53b7b0311c6;p=flightgear.git Defensive handling of locales. - Use setlocale() to ensure consistent handling of locales and string handling irrespective of whether or not QCoreApplication is invoked. Forces a the C locale for numerics and collation, since many pieces of FG assume this. --- diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index f8aad70ad..2a8b049c0 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -21,6 +21,8 @@ #include "QtLauncher.hxx" #include "QtLauncher_private.hxx" +#include + // Qt #include #include @@ -332,14 +334,15 @@ namespace flightgear void initApp(int& argc, char** argv) { - sglog().setLogLevels( SG_ALL, SG_INFO ); - initQtResources(); // can't be called from a namespace - static bool qtInitDone = false; static int s_argc; if (!qtInitDone) { qtInitDone = true; + + sglog().setLogLevels( SG_ALL, SG_INFO ); + initQtResources(); // can't be called from a namespace + s_argc = argc; // QApplication only stores a reference to argc, // and may crash if it is freed // http://doc.qt.io/qt-5/qguiapplication.html#QGuiApplication @@ -349,6 +352,11 @@ void initApp(int& argc, char** argv) app->setApplicationName("FlightGear"); app->setOrganizationDomain("flightgear.org"); + // reset numeric / collation locales as described at: + // http://doc.qt.io/qt-5/qcoreapplication.html#details + ::setlocale(LC_NUMERIC, "C"); + ::setlocale(LC_COLLATE, "C"); + // avoid double Apple menu and other weirdness if both Qt and OSG // try to initialise various Cocoa structures. flightgear::WindowBuilder::setPoseAsStandaloneApp(false); diff --git a/src/Main/bootstrap.cxx b/src/Main/bootstrap.cxx index f15c9098a..050292259 100644 --- a/src/Main/bootstrap.cxx +++ b/src/Main/bootstrap.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -213,6 +214,13 @@ int main ( int argc, char **argv ) initFPE(flightgear::Options::checkForArg(argc, argv, "enable-fpe")); + // pick up all user locale settings, but force C locale for numerical/sorting + // conversions because we have lots of code which assumes standard + // formatting + setlocale(LC_ALL, ""); + setlocale(LC_NUMERIC, "C"); + setlocale(LC_COLLATE, "C"); + bool fgviewer = flightgear::Options::checkForArg(argc, argv, "fgviewer"); try { // http://code.google.com/p/flightgear-bugs/issues/detail?id=1231