Skip to content
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

[clang-tidy] Fix a clang-analyzer-nullability.NullablePassedToNonnull… #15586

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
15 changes: 10 additions & 5 deletions src/platform/Darwin/KeyValueStoreManagerImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ - (instancetype)initWithContext:(nonnull NSManagedObjectContext *)context key:(n
ReturnErrorCodeIf(fileName[0] == '\0', CHIP_ERROR_INVALID_ARGUMENT);

NSURL * url = nullptr;
NSString * filepath = [NSString stringWithUTF8String:fileName];
ReturnErrorCodeIf(filepath == nil, CHIP_ERROR_INVALID_ARGUMENT);

// relative paths are relative to Documents folder
if (fileName[0] != '/') {
if ([filepath hasPrefix:@"/"]) {
NSURL * documentsDirectory = [NSFileManager.defaultManager URLForDirectory:NSDocumentDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
Expand All @@ -167,9 +169,9 @@ - (instancetype)initWithContext:(nonnull NSManagedObjectContext *)context key:(n
ChipLogProgress(
DeviceLayer, "Found user documents directory: %s", [[documentsDirectory absoluteString] UTF8String]);

url = [NSURL URLWithString:[NSString stringWithUTF8String:fileName] relativeToURL:documentsDirectory];
url = [NSURL URLWithString:filepath relativeToURL:documentsDirectory];
} else {
url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:fileName]];
url = [NSURL fileURLWithPath:filepath];
}
ReturnErrorCodeIf(url == nullptr, CHIP_ERROR_NO_MEMORY);

Expand Down Expand Up @@ -274,9 +276,12 @@ - (instancetype)initWithContext:(nonnull NSManagedObjectContext *)context key:(n

NSData * data = [[NSData alloc] initWithBytes:value length:value_size];

KeyValueItem * item = FindItemForKey([[NSString alloc] initWithUTF8String:key], nil);
NSString * itemKey = [[NSString alloc] initWithUTF8String:key];
ReturnErrorCodeIf(itemKey == nil, CHIP_ERROR_INVALID_ARGUMENT);

KeyValueItem * item = FindItemForKey(itemKey, nil);
if (!item) {
item = [[KeyValueItem alloc] initWithContext:gContext key:[[NSString alloc] initWithUTF8String:key] value:data];
item = [[KeyValueItem alloc] initWithContext:gContext key:itemKey value:data];
[gContext performBlockAndWait:^{
[gContext insertObject:item];
}];
Expand Down