From 4d0391d824aaf94fbe152778581d51fecd588f6c Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Fri, 31 Mar 2017 09:07:02 +0200
Subject: Handle potential boost::bad_any_cast exception

Coverity raised this issue.

Test-Information:

Builds and unit tests pass on macOS 10.12.4. Switching
different application languages via --language parameter
still works and passing numbers as languages has it correctly
fallback to the default system language.

Change-Id: Ide1ffdba7a13c27856304aa96b78067147568a95

diff --git a/Swift/QtUI/main.cpp b/Swift/QtUI/main.cpp
index 472c99a..81dc670 100644
--- a/Swift/QtUI/main.cpp
+++ b/Swift/QtUI/main.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2017 Isode Limited.
  * All rights reserved.
  * See the COPYING file for more information.
  */
@@ -89,8 +89,15 @@ int main(int argc, char* argv[]) {
     QTranslator qtTranslator;
     if (!someTranslationPath.empty()) {
 #if QT_VERSION >= 0x040800
+        std::string language;
         if (vm.count("language") > 0) {
-            qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
+            try {
+                language = vm["language"].as<std::string>();
+            } catch (const boost::bad_any_cast&) {
+            }
+        }
+        if (!language.empty()) {
+            qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(language), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
         }
         else {
             qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", P2QSTRING(Swift::pathToString(someTranslationPath)));
-- 
cgit v0.10.2-6-g49f6