]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/translation.cpp
fix integer overflow in mapgen (#11641)
[dragonfireclient.git] / src / translation.cpp
index 82e813a5d59b0f8f3813a828c566baa7260fcf18..1e43b0894d5709d1a9b9ed0ea6af067b7f00aa0f 100644 (file)
@@ -64,7 +64,13 @@ void Translations::loadTranslation(const std::string &data)
                        line.resize(line.length() - 1);
 
                if (str_starts_with(line, "# textdomain:")) {
-                       textdomain = utf8_to_wide(trim(str_split(line, ':')[1]));
+                       auto parts = str_split(line, ':');
+                       if (parts.size() < 2) {
+                               errorstream << "Invalid textdomain translation line \"" << line
+                                               << "\"" << std::endl;
+                               continue;
+                       }
+                       textdomain = utf8_to_wide(trim(parts[1]));
                }
                if (line.empty() || line[0] == '#')
                        continue;
@@ -144,14 +150,13 @@ void Translations::loadTranslation(const std::string &data)
                }
 
                std::wstring oword1 = word1.str(), oword2 = word2.str();
-               if (oword2.empty()) {
-                       oword2 = oword1;
-                       errorstream << "Ignoring empty translation for \""
-                                   << wide_to_utf8(oword1) << "\"" << std::endl;
+               if (!oword2.empty()) {
+                       std::wstring translation_index = textdomain + L"|";
+                       translation_index.append(oword1);
+                       m_translations[translation_index] = oword2;
+               } else {
+                       infostream << "Ignoring empty translation for \""
+                               << wide_to_utf8(oword1) << "\"" << std::endl;
                }
-
-               std::wstring translation_index = textdomain + L"|";
-               translation_index.append(oword1);
-               m_translations[translation_index] = oword2;
        }
 }