Skip to content

Commit 7042d36

Browse files
mark1smiparkera
authored andcommitted
Fix a few small bugs in CFLocale (#946)
* Adds missing mutex unlock in an error path * Fixes use of an incorrect local variable * Addresses a few areas where _prefs member was assumed to be non-NULL * Fix to __CFLocaleGetMeasurementSystemGuts and __CFLocaleCopyTemperatureUnit modelled after __CFLocaleCopyCollatorID * Fix to __CFLocaleEqual handles the case where one or both CFLocales have NULL _prefs.
1 parent 7c2e163 commit 7042d36

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

CoreFoundation/Locale.subproj/CFLocale.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ static Boolean __CFLocaleEqual(CFTypeRef cf1, CFTypeRef cf2) {
198198
if (__CFLocaleGetType(locale1) != __CFLocaleGetType(locale2)) return false;
199199
if (!CFEqual(locale1->_identifier, locale2->_identifier)) return false;
200200
if (__kCFLocaleUser == __CFLocaleGetType(locale1)) {
201-
return CFEqual(locale1->_prefs, locale2->_prefs);
201+
if (locale1->_prefs && locale2->_prefs) {
202+
return CFEqual(locale1->_prefs, locale2->_prefs);
203+
} else {
204+
return locale1->_prefs == locale2->_prefs;
205+
}
202206
}
203207
return true;
204208
}
@@ -447,6 +451,7 @@ CFLocaleRef CFLocaleCreate(CFAllocatorRef allocator, CFStringRef identifier) {
447451
uint32_t size = sizeof(struct __CFLocale) - sizeof(CFRuntimeBase);
448452
locale = (struct __CFLocale *)_CFRuntimeCreateInstance(allocator, CFLocaleGetTypeID(), size, NULL);
449453
if (NULL == locale) {
454+
__CFUnlock(&__CFLocaleCacheLock);
450455
if (localeIdentifier) { CFRelease(localeIdentifier); }
451456
return NULL;
452457
}
@@ -1171,7 +1176,7 @@ static void __CFLocaleGetMeasurementSystemGuts(CFLocaleRef locale, bool user, UM
11711176
UMeasurementSystem output = UMS_SI; // Default is Metric
11721177
bool done = false;
11731178
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
1174-
if (user) {
1179+
if (user && locale->_prefs) {
11751180
CFTypeRef metricPref = CFDictionaryGetValue(locale->_prefs, CFSTR("AppleMetricUnits"));
11761181
CFTypeRef measurementPref = CFDictionaryGetValue(locale->_prefs, CFSTR("AppleMeasurementUnits"));
11771182
if (metricPref || measurementPref) {
@@ -1252,7 +1257,7 @@ static bool __CFLocaleCopyTemperatureUnit(CFLocaleRef locale, bool user, CFTypeR
12521257
bool celsius = true; // Default is Celsius
12531258
bool done = false;
12541259
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
1255-
if (user) {
1260+
if (user && locale->_prefs) {
12561261
CFTypeRef temperatureUnitPref = CFDictionaryGetValue(locale->_prefs, CFSTR("AppleTemperatureUnit"));
12571262
if (temperatureUnitPref) {
12581263
if (CFEqual(temperatureUnitPref, kCFLocaleTemperatureUnitFahrenheit)) {
@@ -1426,7 +1431,7 @@ static bool __CFLocaleFullName(const char *locale, const char *value, CFStringRe
14261431
int32_t localSize;
14271432
UChar localName[kMaxICUNameSize];
14281433
localSize = uloc_getDisplayLanguage(value, locale, localName, kMaxICUNameSize, &localStatus);
1429-
if (U_FAILURE(localStatus) || size <= 0 || localStatus == U_USING_DEFAULT_WARNING)
1434+
if (U_FAILURE(localStatus) || localSize <= 0 || localStatus == U_USING_DEFAULT_WARNING)
14301435
return false;
14311436
}
14321437

0 commit comments

Comments
 (0)