I’m using a 3rd party library for an iOS project I work on, and I’m down to one warning left in the project, namely on this line of code
[NSNumber numberWithUnsignedLongLong:'oaut']
And the warning is
Multi-character character constant
I suck at C, so I don’t know how to fix this, but I’m sure the fix is relatively easy. Help?
EDIT: More context.
@implementation MPOAuthCredentialConcreteStore (KeychainAdditions)
- (void)addToKeychainUsingName:(NSString *)inName andValue:(NSString *)inValue {
NSString *serverName = [self.baseURL host];
NSString *securityDomain = [self.authenticationURL host];
// NSString *itemID = [NSString stringWithFormat:@"%@.oauth.%@", [[NSBundle mainBundle] bundleIdentifier], inName];
NSDictionary *searchDictionary = nil;
NSDictionary *keychainItemAttributeDictionary = [NSDictionary dictionaryWithObjectsAndKeys: (id)kSecClassInternetPassword, kSecClass,
securityDomain, kSecAttrSecurityDomain,
serverName, kSecAttrServer,
inName, kSecAttrAccount,
kSecAttrAuthenticationTypeDefault, kSecAttrAuthenticationType,
[NSNumber numberWithUnsignedLongLong:"oaut"], kSecAttrType,
[inValue dataUsingEncoding:NSUTF8StringEncoding], kSecValueData,
nil];
if ([self findValueFromKeychainUsingName:inName returningItem:&searchDictionary]) {
NSMutableDictionary *updateDictionary = [keychainItemAttributeDictionary mutableCopy];
[updateDictionary removeObjectForKey:(id)kSecClass];
SecItemUpdate((CFDictionaryRef)keychainItemAttributeDictionary, (CFDictionaryRef)updateDictionary);
[updateDictionary release];
} else {
OSStatus success = SecItemAdd( (CFDictionaryRef)keychainItemAttributeDictionary, NULL);
if (success == errSecNotAvailable) {
[NSException raise:@"Keychain Not Available" format:@"Keychain Access Not Currently Available"];
} else if (success == errSecDuplicateItem) {
[NSException raise:@"Keychain duplicate item exception" format:@"Item already exists for %@", keychainItemAttributeDictionary];
}
}
}
EDIT 2: They were attempting to meet the requirements of this by creating that NSNumber:
@constant kSecAttrType Specifies a dictionary key whose value is the item's
type attribute. You use this key to set or get a value of type
CFNumberRef that represents the item's type. This number is the
unsigned integer representation of a four-character code (e.g.,
'aTyp').
In C and Obj-C the single-quote
'is used only for single-character constants. You need to use the double-quote:"Like so:
That covers the warning, but there’s also a semantic issue here. Although a single character constant, such as
'o', can be treated as an integer (and can be promoted to anunsigned long long), a “string” (char *orchar []) cannot, which means you can’t use"oaut"as an argument tonumberWithUnsignedLongLong:Update:
I guess the four-character code is supposed to be treated as an integer, i.e., the 8 bits of each
charput in place as if they together were a 32-bitint:although I’m not sure which endianness would be expected here, nor why this is calling for an
unsigned long long, unless just to be certain there are enough bits.Rudy’s comment, now that I think of it, is correct — multi-character constants are allowed by some compilers for exactly this purpose (it is “implementation-defined” behavior).