Skip to content

Commit

Permalink
fix: crash caused by app.getLocaleCountryCode() (#32322)
Browse files Browse the repository at this point in the history
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>

Co-authored-by: Darshan Sen <darshan.sen@postman.com>
  • Loading branch information
trop[bot] and RaisinTen committed Jan 4, 2022
1 parent efd6f85 commit 9ef50c0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions shell/browser/api/electron_api_app.cc
Expand Up @@ -1054,11 +1054,14 @@ std::string App::GetLocaleCountryCode() {
CFLocaleRef locale = CFLocaleCopyCurrent();
CFStringRef value = CFStringRef(
static_cast<CFTypeRef>(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
const CFIndex kCStringSize = 128;
char temporaryCString[kCStringSize] = {0};
CFStringGetCString(value, temporaryCString, kCStringSize,
kCFStringEncodingUTF8);
region = temporaryCString;
if (value != nil) {
char temporaryCString[3];
const CFIndex kCStringSize = sizeof(temporaryCString);
if (CFStringGetCString(value, temporaryCString, kCStringSize,
kCFStringEncodingUTF8)) {
region = temporaryCString;
}
}
#else
const char* locale_ptr = setlocale(LC_TIME, nullptr);
if (!locale_ptr)
Expand Down

0 comments on commit 9ef50c0

Please sign in to comment.