Skip to content

Commit

Permalink
[Darwin] Fix a crash when a nil device is passed to a cluster on init (
Browse files Browse the repository at this point in the history
…#6276)

* [Darwin] Fix a crash when a nil device is passed to a cluster on init

* Update generated files

* Mark getDevice as nullable since it can return nil
  • Loading branch information
sagar-apple authored Apr 27, 2021
1 parent d617fde commit ffa29ec
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/chip-tool/gen/CHIPClustersObjc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,10 @@ - (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoin
return nil;
}

if (device == nullptr) {
return nil;
}

CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint);
if (err != CHIP_NO_ERROR) {
return nil;
Expand Down
5 changes: 5 additions & 0 deletions src/app/zap-templates/templates/app/CHIPClustersObjc-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ private:
return nil;
}

if (device == nullptr)
{
return nil;
}

CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint);
if (err != CHIP_NO_ERROR) {
return nil;
Expand Down
4 changes: 4 additions & 0 deletions src/controller/python/gen/CHIPClustersObjc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,10 @@ - (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoin
return nil;
}

if (device == nullptr) {
return nil;
}

CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint);
if (err != CHIP_NO_ERROR) {
return nil;
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)stopDevicePairing:(uint64_t)deviceID error:(NSError * __autoreleasing *)error;
- (void)updateDevice:(uint64_t)deviceID fabricId:(uint64_t)fabricId;

- (CHIPDevice *)getPairedDevice:(uint64_t)deviceID error:(NSError * __autoreleasing *)error;
- (nullable CHIPDevice *)getPairedDevice:(uint64_t)deviceID error:(NSError * __autoreleasing *)error;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/gen/CHIPClustersObjc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,10 @@ - (instancetype)initWithDevice:(CHIPDevice *)device endpoint:(EndpointId)endpoin
return nil;
}

if (device == nullptr) {
return nil;
}

CHIP_ERROR err = cppCluster->Associate([device internalDevice], endpoint);
if (err != CHIP_NO_ERROR) {
return nil;
Expand Down

0 comments on commit ffa29ec

Please sign in to comment.