From 630c6c59ae751c9f6709633640c6719578275544 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Fri, 25 Feb 2022 23:22:02 +0100 Subject: [PATCH] [clang-tidy] Fix -clang-analyzer-nullability.NullPassedToNonnull error in src/platform/Darwin/BlePlatformDelegateImpl.mm (#15575) --- .../Darwin/BlePlatformDelegateImpl.mm | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/platform/Darwin/BlePlatformDelegateImpl.mm b/src/platform/Darwin/BlePlatformDelegateImpl.mm index 675381dc07d525..8f74bb8244feff 100644 --- a/src/platform/Darwin/BlePlatformDelegateImpl.mm +++ b/src/platform/Darwin/BlePlatformDelegateImpl.mm @@ -45,17 +45,14 @@ BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId) { bool found = false; - CBUUID * serviceId = nil; - CBUUID * characteristicId = nil; - CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; - if (NULL != svcId) { - serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + if (NULL == svcId || NULL == charId) { + return found; } - if (NULL != charId) { - characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; - } + CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; + CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; for (CBService * service in peripheral.services) { if ([service.UUID.data isEqualToData:serviceId.data]) { @@ -76,17 +73,15 @@ BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId) { bool found = false; - CBUUID * serviceId = nil; - CBUUID * characteristicId = nil; - CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; - - if (NULL != svcId) { - serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; - } - if (NULL != charId) { - characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; + if (NULL == svcId || NULL == charId) { + return found; } + CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * characteristicId = characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes + length:sizeof(charId->bytes)]]; + CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; + for (CBService * service in peripheral.services) { if ([service.UUID.data isEqualToData:serviceId.data]) { for (CBCharacteristic * characteristic in service.characteristics) { @@ -135,21 +130,15 @@ BLE_CONNECTION_OBJECT connObj, const ChipBleUUID * svcId, const ChipBleUUID * charId, PacketBufferHandle pBuf) { bool found = false; - CBUUID * serviceId = nil; - CBUUID * characteristicId = nil; - NSData * data = nil; - CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; - - if (NULL != svcId) { - serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; - } - if (NULL != charId) { - characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; - } - if (!pBuf.IsNull()) { - data = [NSData dataWithBytes:pBuf->Start() length:pBuf->DataLength()]; + if (NULL == svcId || NULL == charId || pBuf.IsNull()) { + return found; } + CBUUID * serviceId = [UUIDHelper GetShortestServiceUUID:svcId]; + CBUUID * characteristicId = [CBUUID UUIDWithData:[NSData dataWithBytes:charId->bytes length:sizeof(charId->bytes)]]; + NSData * data = [NSData dataWithBytes:pBuf->Start() length:pBuf->DataLength()]; + CBPeripheral * peripheral = (__bridge CBPeripheral *) connObj; + for (CBService * service in peripheral.services) { if ([service.UUID.data isEqualToData:serviceId.data]) { for (CBCharacteristic * characteristic in service.characteristics) {