Fixed: Additional NULL checks in UTF-8 detection

This commit is contained in:
aristocratos 2021-09-25 00:10:18 +02:00
parent ee8109ec38
commit 5273a62856

View file

@ -718,10 +718,11 @@ int main(int argc, char **argv) {
}
//? Try to find and set a UTF-8 locale
if (bool found = false; not str_to_upper(s_replace((string)std::setlocale(LC_ALL, NULL), "-", "")).ends_with("UTF8")) {
if (bool found = false; std::setlocale(LC_ALL, NULL) != NULL and not str_to_upper(s_replace((string)std::setlocale(LC_ALL, NULL), "-", "")).ends_with("UTF8")) {
if (getenv("LANG") != NULL and str_to_upper(s_replace((string)getenv("LANG"), "-", "")).ends_with("UTF8")) {
found = true;
std::setlocale(LC_ALL, getenv("LANG"));
if (std::setlocale(LC_ALL, getenv("LANG")) != NULL) {
found = true;
}
}
else {
setenv("LANG", "", 1);
@ -729,8 +730,8 @@ int main(int argc, char **argv) {
if (const auto loc = std::locale("").name(); not loc.empty()) {
for (auto& l : ssplit(loc, ';')) {
if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) {
found = true;
std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str());
if (std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str()) != NULL)
found = true;
break;
}
}