Skip to content

Commit

Permalink
[clang-tidy] Fix a clang-analyzer-nullability.NullablePassedToNonnull…
Browse files Browse the repository at this point in the history
… occurence in src/platform/Darwin/KeyValueStoreManagerImpl.mm (#15586)
  • Loading branch information
vivien-apple authored and pull[bot] committed Feb 6, 2024
1 parent a9f8630 commit 4784179
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit 4784179

Please sign in to comment.