cui/source/options/optcolor.cxx |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

New commits:
commit 6f29310fe83873c7d6844cf5e3089ca981e147db
Author:     Tor Lillqvist <t...@collabora.com>
AuthorDate: Thu Feb 23 12:29:48 2023 +0200
Commit:     Tor Lillqvist <t...@collabora.com>
CommitDate: Thu Feb 23 13:47:56 2023 +0000

    Don't call CuiResId() in a global static variable initialiser
    
    Instead, have a function that returns a reference to a local static
    variable. That local static is then initialised only when the function
    is called for the first time. Calling CuiResId() in a global
    initialiser is a bit questionable, and causes an uncaught exception
    when LO core is used in a WASM app. Possibly it would also have been
    problematic on other uncommon platforms.
    
    Change-Id: I4fd799ba3aa8d63fd3db1eb8cf6211aeed904ed2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147512
    Tested-by: Tor Lillqvist <t...@collabora.com>
    Reviewed-by: Tor Lillqvist <t...@collabora.com>

diff --git a/cui/source/options/optcolor.cxx b/cui/source/options/optcolor.cxx
index 2cb20a2650fa..4ad5d2b5e93f 100644
--- a/cui/source/options/optcolor.cxx
+++ b/cui/source/options/optcolor.cxx
@@ -161,9 +161,13 @@ const vEntryInfo[] =
 };
 
 // Maps the names of default color schemes to the corresponding TranslateId
-std::map<OUString, OUString> const vColorSchemes = {
-    {"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", 
CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC)},
-    {"COLOR_SCHEME_LIBREOFFICE_DARK",      
CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_DARK)}
+const std::map<OUString, OUString> &getColorSchemes()
+{
+    static std::map<OUString, OUString> const vColorSchemes = {
+        {"COLOR_SCHEME_LIBREOFFICE_AUTOMATIC", 
CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_AUTOMATIC)},
+        {"COLOR_SCHEME_LIBREOFFICE_DARK",      
CuiResId(RID_COLOR_SCHEME_LIBREOFFICE_DARK)}
+    };
+    return vColorSchemes;
 };
 
 // If the color scheme name has a translated string, then return the 
translation
@@ -171,8 +175,8 @@ std::map<OUString, OUString> const vColorSchemes = {
 // For non-translatable color schemes, the ID and the name are the same
 OUString lcl_SchemeIdToTranslatedName(const OUString& sSchemeId)
 {
-    auto it = vColorSchemes.find(sSchemeId);
-    if (it != vColorSchemes.end())
+    auto it = getColorSchemes().find(sSchemeId);
+    if (it != getColorSchemes().end())
         return it->second;
     return sSchemeId;
 }
@@ -181,7 +185,7 @@ OUString lcl_SchemeIdToTranslatedName(const OUString& 
sSchemeId)
 // For non-translatable color schemes, the ID and the name are the same
 OUString lcl_TranslatedNameToSchemeId(const OUString& sName)
 {
-    for (auto it = vColorSchemes.begin(); it != vColorSchemes.end(); ++it)
+    for (auto it = getColorSchemes().begin(); it != getColorSchemes().end(); 
++it)
         if (it->second == sName)
             return it->first;
     return sName;

Reply via email to