зеркало из https://github.com/electron/electron.git
fix: crash caused by app.getLocaleCountryCode() (#32256)
CFLocaleGetValue() returned null and crashed the process when app.getLocaleCountryCode() was run on a CircleCI metal resource class macOS instance with Xcode 12.5.1. This change fixes that logic and adds further checks to make the code future-proof. Here too people are complaining that the returned country code migth be null: https://stackoverflow.com/questions/15202454/nslocalecountrycode-returns-nil Signed-off-by: Darshan Sen <darshan.sen@postman.com>
This commit is contained in:
Родитель
2c700da4de
Коммит
4600d7e7f6
|
@ -1054,11 +1054,14 @@ std::string App::GetLocaleCountryCode() {
|
||||||
CFLocaleRef locale = CFLocaleCopyCurrent();
|
CFLocaleRef locale = CFLocaleCopyCurrent();
|
||||||
CFStringRef value = CFStringRef(
|
CFStringRef value = CFStringRef(
|
||||||
static_cast<CFTypeRef>(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
|
static_cast<CFTypeRef>(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
|
||||||
const CFIndex kCStringSize = 128;
|
if (value != nil) {
|
||||||
char temporaryCString[kCStringSize] = {0};
|
char temporaryCString[3];
|
||||||
CFStringGetCString(value, temporaryCString, kCStringSize,
|
const CFIndex kCStringSize = sizeof(temporaryCString);
|
||||||
kCFStringEncodingUTF8);
|
if (CFStringGetCString(value, temporaryCString, kCStringSize,
|
||||||
region = temporaryCString;
|
kCFStringEncodingUTF8)) {
|
||||||
|
region = temporaryCString;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
const char* locale_ptr = setlocale(LC_TIME, nullptr);
|
const char* locale_ptr = setlocale(LC_TIME, nullptr);
|
||||||
if (!locale_ptr)
|
if (!locale_ptr)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче