Skip to content

Fixes 5 static analyser issues in CFPreferences.c #2819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions CoreFoundation/Preferences.subproj/CFPreferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ CF_PRIVATE CFStringRef _CFPreferencesGetByHostIdentifierString(void) {

static unsigned long __CFSafeLaunchLevel = 0;

static CFURLRef _preferencesDirectoryForUserHostSafetyLevel(CFStringRef userName, CFStringRef hostName, unsigned long safeLevel) {
CFAllocatorRef alloc = __CFPreferencesAllocator();
static CFURLRef _preferencesCreateDirectoryForUserHostSafetyLevel(CFStringRef userName, CFStringRef hostName, unsigned long safeLevel) {
CFURLRef location = NULL;

CFKnownLocationUser user;
Expand All @@ -197,7 +196,7 @@ static CFURLRef _preferencesDirectoryForUserHostSafetyLevel(CFStringRef userName
}

static CFURLRef _preferencesDirectoryForUserHost(CFStringRef userName, CFStringRef hostName) {
return _preferencesDirectoryForUserHostSafetyLevel(userName, hostName, __CFSafeLaunchLevel);
return _preferencesCreateDirectoryForUserHostSafetyLevel(userName, hostName, __CFSafeLaunchLevel);
}

static Boolean __CFPreferencesWritesXML = true;
Expand Down Expand Up @@ -282,15 +281,13 @@ void CFPreferencesSetMultiple(CFDictionaryRef keysToSet, CFArrayRef keysToRemove

CFTypeRef *keys = NULL;
CFTypeRef *values;
CFIndex numOfKeysToSet = 0;

domain = _CFPreferencesStandardDomain(appName, user, host);
if (!domain) return;

CFAllocatorRef alloc = CFGetAllocator(domain);

if (keysToSet && (count = CFDictionaryGetCount(keysToSet))) {
numOfKeysToSet = count;
keys = (CFTypeRef *)CFAllocatorAllocate(alloc, 2*count*sizeof(CFTypeRef), 0);
if (keys) {
values = &(keys[count]);
Expand Down Expand Up @@ -385,7 +382,7 @@ const CFRuntimeClass __CFPreferencesDomainClass = {
};

/* We spend a lot of time constructing these prefixes; we should cache. REW, 7/19/99 */
static CFStringRef _CFPreferencesCachePrefixForUserHost(CFStringRef userName, CFStringRef hostName) {
static CFStringRef _CFPreferencesCreateCachePrefixForUserHost(CFStringRef userName, CFStringRef hostName) {
if (userName == kCFPreferencesAnyUser && hostName == kCFPreferencesAnyHost) {
return (CFStringRef)CFRetain(CFSTR("*/*/"));
}
Expand All @@ -410,7 +407,7 @@ static CFStringRef _CFPreferencesCachePrefixForUserHost(CFStringRef userName,

// It would be nice if we could remember the key for "well-known" combinations, so we're not constantly allocing more strings.... - REW 2/3/99
static CFStringRef _CFPreferencesStandardDomainCacheKey(CFStringRef domainName, CFStringRef userName, CFStringRef hostName) {
CFStringRef prefix = _CFPreferencesCachePrefixForUserHost(userName, hostName);
CFStringRef prefix = _CFPreferencesCreateCachePrefixForUserHost(userName, hostName);
CFStringRef result = NULL;

if (prefix) {
Expand All @@ -424,7 +421,7 @@ static CFURLRef _CFPreferencesURLForStandardDomainWithSafetyLevel(CFStringRef do
CFURLRef theURL = NULL;
CFAllocatorRef prefAlloc = __CFPreferencesAllocator();
#if TARGET_OS_OSX || TARGET_OS_WIN32 || TARGET_OS_LINUX
CFURLRef prefDir = _preferencesDirectoryForUserHostSafetyLevel(userName, hostName, safeLevel);
CFURLRef prefDir = _preferencesCreateDirectoryForUserHostSafetyLevel(userName, hostName, safeLevel);
CFStringRef appName;
CFStringRef fileName;
Boolean mustFreeAppName = false;
Expand Down Expand Up @@ -462,12 +459,12 @@ static CFURLRef _CFPreferencesURLForStandardDomainWithSafetyLevel(CFStringRef do
#elif TARGET_OS_WIN32
theURL = CFURLCreateWithFileSystemPathRelativeToBase(prefAlloc, fileName, kCFURLWindowsPathStyle, false, prefDir);
#endif
if (prefDir) CFRelease(prefDir);
CFRelease(fileName);
}
#else
//#error Do not know where to store NSUserDefaults on this platform
#endif
if (prefDir) CFRelease(prefDir);
return theURL;
}

Expand Down Expand Up @@ -607,7 +604,7 @@ CF_PRIVATE CFArrayRef _CFPreferencesCreateDomainList(CFStringRef userName, CFSt
cachedDomains = (CFPreferencesDomainRef *)(cachedDomainKeys + cnt);
CFDictionaryGetKeysAndValues(domainCache, (const void **)cachedDomainKeys, (const void **)cachedDomains);
__CFUnlock(&domainCacheLock);
suffix = _CFPreferencesCachePrefixForUserHost(userName, hostName);
suffix = _CFPreferencesCreateCachePrefixForUserHost(userName, hostName);
suffixLen = CFStringGetLength(suffix);

for (idx = 0; idx < cnt; idx ++) {
Expand Down Expand Up @@ -738,9 +735,8 @@ static void freeVolatileDomain(CFAllocatorRef allocator, CFTypeRef context, voi
CFRelease((CFTypeRef)domain);
}

static CFTypeRef fetchVolatileValue(CFTypeRef context, void *domain, CFStringRef key) {
CFTypeRef result = CFDictionaryGetValue((CFMutableDictionaryRef )domain, key);
if (result) CFRetain(result);
static CFTypeRef fetchVolatileValue(CFTypeRef context, void *domain, CFStringRef key) {
CFTypeRef result = CFDictionaryGetValue((CFMutableDictionaryRef )domain, key);
return result;
}

Expand Down