1
0
Fork 0

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.
This commit is contained in:
James Turner 2016-02-02 20:44:46 +00:00
parent 5ef3413373
commit c72309360e
2 changed files with 19 additions and 3 deletions

View file

@ -21,6 +21,8 @@
#include "QtLauncher.hxx"
#include "QtLauncher_private.hxx"
#include <locale.h>
// Qt
#include <QProgressDialog>
#include <QCoreApplication>
@ -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);

View file

@ -50,6 +50,7 @@
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <locale.h>
#include <simgear/compiler.h>
#include <simgear/structure/exception.hxx>
@ -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