Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2468)

Unified Diff: base/ios/device_util.mm

Issue 314123002: Fixed string conversions to avoid nil pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/ios/device_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/ios/device_util.mm
diff --git a/base/ios/device_util.mm b/base/ios/device_util.mm
index 84495377c547340f30685ca339bb817832776179..c3e9c2079fe5a92ad03f0c15952893af52c78d99 100644
--- a/base/ios/device_util.mm
+++ b/base/ios/device_util.mm
@@ -46,7 +46,7 @@ NSString* GenerateClientId() {
if (!client_id || [client_id isEqualToString:kZeroUUID]) {
if (base::ios::IsRunningOnIOS6OrLater()) {
client_id = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
- if ([client_id isEqualToString:kZeroUUID])
+ if (!client_id || [client_id isEqualToString:kZeroUUID])
client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId());
} else {
client_id = base::SysUTF8ToNSString(ios::device_util::GetRandomId());
@@ -157,16 +157,16 @@ std::string GetDeviceIdentifier(const char* salt) {
[defaults synchronize];
}
- return GetSaltedString([client_id UTF8String], salt ? salt : kDefaultSalt);
+ return GetSaltedString(base::SysNSStringToUTF8(client_id),
+ salt ? salt : kDefaultSalt);
}
std::string GetSaltedString(const std::string& in_string,
const std::string& salt) {
DCHECK(in_string.length());
DCHECK(salt.length());
- NSData* hash_data =
- [[NSString stringWithFormat:@"%s%s", in_string.c_str(), salt.c_str()]
- dataUsingEncoding:NSUTF8StringEncoding];
+ NSData* hash_data = [base::SysUTF8ToNSString(in_string + salt)
+ dataUsingEncoding:NSUTF8StringEncoding];
unsigned char hash[CC_SHA256_DIGEST_LENGTH];
CC_SHA256([hash_data bytes], [hash_data length], hash);
« no previous file with comments | « base/ios/device_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698