diff --git a/examples/shell/shell_common/cmd_device.cpp b/examples/shell/shell_common/cmd_device.cpp index 5cbcbbd8b939ab..d4da457f7744f8 100644 --- a/examples/shell/shell_common/cmd_device.cpp +++ b/examples/shell/shell_common/cmd_device.cpp @@ -184,7 +184,7 @@ static CHIP_ERROR ConfigGetDeviceCert(bool printHeader) VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); // Create a temporary buffer to hold the certificate. - certBuf = (uint8_t *) MemoryAlloc(certLen); + certBuf = static_cast(MemoryAlloc(certLen)); VerifyOrExit(certBuf != nullptr, error = CHIP_ERROR_NO_MEMORY); // Read the certificate @@ -220,7 +220,7 @@ static CHIP_ERROR ConfigGetDeviceCaCerts(bool printHeader) VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); // Create a temporary buffer to hold the certificate. - certBuf = (uint8_t *) MemoryAlloc(certLen); + certBuf = static_cast(MemoryAlloc(certLen)); VerifyOrExit(certBuf != nullptr, error = CHIP_ERROR_NO_MEMORY); // Read the certificate @@ -273,7 +273,7 @@ static CHIP_ERROR ConfigGetManufacturerDeviceCert(bool printHeader) VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); // Create a temporary buffer to hold the certificate. - certBuf = (uint8_t *) MemoryAlloc(certLen); + certBuf = static_cast(MemoryAlloc(certLen)); VerifyOrExit(certBuf != nullptr, error = CHIP_ERROR_NO_MEMORY); // Read the certificate @@ -309,7 +309,7 @@ static CHIP_ERROR ConfigGetManufacturerDeviceCaCerts(bool printHeader) VerifyOrExit(certLen != 0, error = CHIP_ERROR_CERT_NOT_FOUND); // Create a temporary buffer to hold the certificate. - certBuf = (uint8_t *) MemoryAlloc(certLen); + certBuf = static_cast(MemoryAlloc(certLen)); VerifyOrExit(certBuf != nullptr, error = CHIP_ERROR_NO_MEMORY); // Read the certificate diff --git a/src/ble/BleLayer.cpp b/src/ble/BleLayer.cpp index 43dc82b4aac618..ad92b6e270d04b 100644 --- a/src/ble/BleLayer.cpp +++ b/src/ble/BleLayer.cpp @@ -110,7 +110,7 @@ class BleEndPointPool if (i < BLE_LAYER_NUM_BLE_ENDPOINTS) { - return (BLEEndPoint *) (sEndPointPool.Pool + (sizeof(BLEEndPoint) * i)); + return reinterpret_cast(sEndPointPool.Pool + (sizeof(BLEEndPoint) * i)); } return nullptr; diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index bcaece15ff0c2c..b2a9418eff244a 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -273,7 +273,7 @@ CHIP_ERROR nl_Chip_DeviceController_DriveIO(uint32_t sleepTimeMS) if (GetBleEventCB) { - evu.ev = (const BleEventBase *) GetBleEventCB(); + evu.ev = static_cast(GetBleEventCB()); if (evu.ev) { diff --git a/src/crypto/CHIPCryptoPALOpenSSL.cpp b/src/crypto/CHIPCryptoPALOpenSSL.cpp index cd89de82ec4c2a..1656cee06d1961 100644 --- a/src/crypto/CHIPCryptoPALOpenSSL.cpp +++ b/src/crypto/CHIPCryptoPALOpenSSL.cpp @@ -1124,7 +1124,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::InitInternal() init_bn(tempbn); init_bn(order); - error_openssl = EC_GROUP_get_order(context->curve, (BIGNUM *) order, context->bn_ctx); + error_openssl = EC_GROUP_get_order(context->curve, static_cast(order), context->bn_ctx); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; @@ -1210,7 +1210,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::FELoad(const uint8_t * in, size_t in_l { CHIP_ERROR error = CHIP_ERROR_INTERNAL; int error_openssl = 0; - BIGNUM * bn_fe = (BIGNUM *) fe; + BIGNUM * bn_fe = static_cast(fe); Spake2p_Context * context = to_inner_spake2p_context(&mSpake2pContext); @@ -1243,7 +1243,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::FEGenerate(void * fe) CHIP_ERROR error = CHIP_ERROR_INTERNAL; int error_openssl = 0; - error_openssl = BN_rand_range((BIGNUM *) fe, (BIGNUM *) order); + error_openssl = BN_rand_range(static_cast(fe), static_cast(order)); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; @@ -1258,7 +1258,8 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::FEMul(void * fer, const void * fe1, co Spake2p_Context * context = to_inner_spake2p_context(&mSpake2pContext); - error_openssl = BN_mod_mul((BIGNUM *) fer, (BIGNUM *) fe1, (BIGNUM *) fe2, (BIGNUM *) order, context->bn_ctx); + error_openssl = + BN_mod_mul(static_cast(fer), (BIGNUM *) fe1, (BIGNUM *) fe2, static_cast(order), context->bn_ctx); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; @@ -1273,7 +1274,8 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointLoad(const uint8_t * in, size_t i Spake2p_Context * context = to_inner_spake2p_context(&mSpake2pContext); - error_openssl = EC_POINT_oct2point(context->curve, (EC_POINT *) R, Uint8::to_const_uchar(in), in_len, context->bn_ctx); + error_openssl = + EC_POINT_oct2point(context->curve, static_cast(R), Uint8::to_const_uchar(in), in_len, context->bn_ctx); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; @@ -1302,7 +1304,8 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointMul(void * R, const void * P1, co Spake2p_Context * context = to_inner_spake2p_context(&mSpake2pContext); - error_openssl = EC_POINT_mul(context->curve, (EC_POINT *) R, nullptr, (EC_POINT *) P1, (BIGNUM *) fe1, context->bn_ctx); + error_openssl = + EC_POINT_mul(context->curve, static_cast(R), nullptr, (EC_POINT *) P1, (BIGNUM *) fe1, context->bn_ctx); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; @@ -1328,7 +1331,8 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointAddMul(void * R, const void * P1, error = PointMul(R, P2, fe2); VerifyOrExit(error == CHIP_NO_ERROR, error = CHIP_ERROR_INTERNAL); - error_openssl = EC_POINT_add(context->curve, (EC_POINT *) R, (EC_POINT *) R, (const EC_POINT *) scratch, context->bn_ctx); + error_openssl = EC_POINT_add(context->curve, static_cast(R), static_cast(R), (const EC_POINT *) scratch, + context->bn_ctx); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; @@ -1344,7 +1348,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointInvert(void * R) Spake2p_Context * context = to_inner_spake2p_context(&mSpake2pContext); - error_openssl = EC_POINT_invert(context->curve, (EC_POINT *) R, context->bn_ctx); + error_openssl = EC_POINT_invert(context->curve, static_cast(R), context->bn_ctx); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; @@ -1400,7 +1404,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointIsValid(void * R) Spake2p_Context * context = to_inner_spake2p_context(&mSpake2pContext); - error_openssl = EC_POINT_is_on_curve(context->curve, (EC_POINT *) R, context->bn_ctx); + error_openssl = EC_POINT_is_on_curve(context->curve, static_cast(R), context->bn_ctx); VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL); error = CHIP_NO_ERROR; diff --git a/src/crypto/tests/CHIPCryptoPALTest.cpp b/src/crypto/tests/CHIPCryptoPALTest.cpp index 5002ee4173f052..a69e62f56044f9 100644 --- a/src/crypto/tests/CHIPCryptoPALTest.cpp +++ b/src/crypto/tests/CHIPCryptoPALTest.cpp @@ -602,59 +602,61 @@ static void TestDRBG_Output(nlTestSuite * inSuite, void * inContext) static void TestECDSA_Signing_SHA256(nlTestSuite * inSuite, void * inContext) { const char * msg = "Hello World!"; - size_t msg_length = strlen((const char *) msg); + size_t msg_length = strlen(msg); P256Keypair keypair; NL_TEST_ASSERT(inSuite, keypair.Initialize() == CHIP_NO_ERROR); P256ECDSASignature signature; - CHIP_ERROR signing_error = keypair.ECDSA_sign_msg((const uint8_t *) msg, msg_length, signature); + CHIP_ERROR signing_error = keypair.ECDSA_sign_msg(reinterpret_cast(msg), msg_length, signature); NL_TEST_ASSERT(inSuite, signing_error == CHIP_NO_ERROR); - CHIP_ERROR validation_error = keypair.Pubkey().ECDSA_validate_msg_signature((const uint8_t *) msg, msg_length, signature); + CHIP_ERROR validation_error = + keypair.Pubkey().ECDSA_validate_msg_signature(reinterpret_cast(msg), msg_length, signature); NL_TEST_ASSERT(inSuite, validation_error == CHIP_NO_ERROR); } static void TestECDSA_ValidationFailsDifferentMessage(nlTestSuite * inSuite, void * inContext) { const char * msg = "Hello World!"; - size_t msg_length = strlen((const char *) msg); + size_t msg_length = strlen(msg); P256Keypair keypair; NL_TEST_ASSERT(inSuite, keypair.Initialize() == CHIP_NO_ERROR); P256ECDSASignature signature; - CHIP_ERROR signing_error = keypair.ECDSA_sign_msg((const uint8_t *) msg, msg_length, signature); + CHIP_ERROR signing_error = keypair.ECDSA_sign_msg(reinterpret_cast(msg), msg_length, signature); NL_TEST_ASSERT(inSuite, signing_error == CHIP_NO_ERROR); const char * diff_msg = "NOT Hello World!"; - size_t diff_msg_length = strlen((const char *) msg); + size_t diff_msg_length = strlen(msg); CHIP_ERROR validation_error = - keypair.Pubkey().ECDSA_validate_msg_signature((const uint8_t *) diff_msg, diff_msg_length, signature); + keypair.Pubkey().ECDSA_validate_msg_signature(reinterpret_cast(diff_msg), diff_msg_length, signature); NL_TEST_ASSERT(inSuite, validation_error != CHIP_NO_ERROR); } static void TestECDSA_ValidationFailIncorrectSignature(nlTestSuite * inSuite, void * inContext) { const char * msg = "Hello World!"; - size_t msg_length = strlen((const char *) msg); + size_t msg_length = strlen(msg); P256Keypair keypair; NL_TEST_ASSERT(inSuite, keypair.Initialize() == CHIP_NO_ERROR); P256ECDSASignature signature; - CHIP_ERROR signing_error = keypair.ECDSA_sign_msg((const uint8_t *) msg, msg_length, signature); + CHIP_ERROR signing_error = keypair.ECDSA_sign_msg(reinterpret_cast(msg), msg_length, signature); NL_TEST_ASSERT(inSuite, signing_error == CHIP_NO_ERROR); signature[0] = static_cast(~signature[0]); // Flipping bits should invalidate the signature. - CHIP_ERROR validation_error = keypair.Pubkey().ECDSA_validate_msg_signature((const uint8_t *) msg, msg_length, signature); + CHIP_ERROR validation_error = + keypair.Pubkey().ECDSA_validate_msg_signature(reinterpret_cast(msg), msg_length, signature); NL_TEST_ASSERT(inSuite, validation_error == CHIP_ERROR_INVALID_SIGNATURE); } static void TestECDSA_SigningInvalidParams(nlTestSuite * inSuite, void * inContext) { - const uint8_t * msg = (uint8_t *) "Hello World!"; - size_t msg_length = strlen((const char *) msg); + const uint8_t * msg = reinterpret_cast("Hello World!"); + size_t msg_length = strlen(reinterpret_cast(msg)); P256Keypair keypair; NL_TEST_ASSERT(inSuite, keypair.Initialize() == CHIP_NO_ERROR); @@ -672,20 +674,20 @@ static void TestECDSA_SigningInvalidParams(nlTestSuite * inSuite, void * inConte static void TestECDSA_ValidationInvalidParam(nlTestSuite * inSuite, void * inContext) { const char * msg = "Hello World!"; - size_t msg_length = strlen((const char *) msg); + size_t msg_length = strlen(msg); P256Keypair keypair; NL_TEST_ASSERT(inSuite, keypair.Initialize() == CHIP_NO_ERROR); P256ECDSASignature signature; - CHIP_ERROR signing_error = keypair.ECDSA_sign_msg((const uint8_t *) msg, msg_length, signature); + CHIP_ERROR signing_error = keypair.ECDSA_sign_msg(reinterpret_cast(msg), msg_length, signature); NL_TEST_ASSERT(inSuite, signing_error == CHIP_NO_ERROR); CHIP_ERROR validation_error = keypair.Pubkey().ECDSA_validate_msg_signature(nullptr, msg_length, signature); NL_TEST_ASSERT(inSuite, validation_error == CHIP_ERROR_INVALID_ARGUMENT); validation_error = CHIP_NO_ERROR; - validation_error = keypair.Pubkey().ECDSA_validate_msg_signature((const uint8_t *) msg, 0, signature); + validation_error = keypair.Pubkey().ECDSA_validate_msg_signature(reinterpret_cast(msg), 0, signature); NL_TEST_ASSERT(inSuite, validation_error == CHIP_ERROR_INVALID_ARGUMENT); validation_error = CHIP_NO_ERROR; } diff --git a/src/crypto/tests/SPAKE2P_RFC_test_vectors.h b/src/crypto/tests/SPAKE2P_RFC_test_vectors.h index a49c61720c12f0..20a77596a7a874 100644 --- a/src/crypto/tests/SPAKE2P_RFC_test_vectors.h +++ b/src/crypto/tests/SPAKE2P_RFC_test_vectors.h @@ -117,11 +117,11 @@ static const uint8_t chiptest_e4836c3b50dd_MAC_KcB_15[] = { 0x06, 0x60, 0xa6, 0x 0xb2, 0x2d, 0xff, 0x29, 0x8b, 0x1d, 0x07, 0xa5, 0x26, 0xcf, 0x3c, 0xc5, 0x91, 0xad, 0xfe, 0xcd, 0x1f, 0x6e, 0xf6, 0xe0, 0x2e }; static const struct spake2p_rfc_tv chiptest_e4836c3b50dd_test_vector_16 = { - .context = (const uint8_t *) "SPAKE2+-P256-SHA256-HKDF draft-01", + .context = reinterpret_cast("SPAKE2+-P256-SHA256-HKDF draft-01"), .context_len = 33, - .prover_identity = (const uint8_t *) "client", + .prover_identity = reinterpret_cast("client"), .prover_identity_len = 6, - .verifier_identity = (const uint8_t *) "server", + .verifier_identity = reinterpret_cast("server"), .verifier_identity_len = 6, .w0 = chiptest_e4836c3b50dd_w0_1, .w0_len = 32, @@ -211,11 +211,11 @@ static const uint8_t chiptest_e4836c3b50dd_MAC_KcB_31[] = { 0xb9, 0xc3, 0x9d, 0x 0x9b, 0xed, 0xea, 0xca, 0x24, 0x48, 0xb9, 0x05, 0xbe, 0x19, 0xa4, 0x3b, 0x94, 0xee, 0x24, 0xb7, 0x70, 0x20, 0x81, 0x35, 0xe3 }; static const struct spake2p_rfc_tv chiptest_e4836c3b50dd_test_vector_32 = { - .context = (const uint8_t *) "SPAKE2+-P256-SHA256-HKDF draft-01", + .context = reinterpret_cast("SPAKE2+-P256-SHA256-HKDF draft-01"), .context_len = 33, - .prover_identity = (const uint8_t *) "client", + .prover_identity = reinterpret_cast("client"), .prover_identity_len = 6, - .verifier_identity = (const uint8_t *) "", + .verifier_identity = reinterpret_cast(""), .verifier_identity_len = 0, .w0 = chiptest_e4836c3b50dd_w0_17, .w0_len = 32, @@ -305,11 +305,11 @@ static const uint8_t chiptest_e4836c3b50dd_MAC_KcB_47[] = { 0x07, 0x2a, 0x94, 0x 0x53, 0x4c, 0x23, 0x17, 0xca, 0xdf, 0x3e, 0xa3, 0x79, 0x28, 0x27, 0xf4, 0x79, 0xe8, 0x73, 0xf9, 0x3e, 0x90, 0xf2, 0x15, 0x52 }; static const struct spake2p_rfc_tv chiptest_e4836c3b50dd_test_vector_48 = { - .context = (const uint8_t *) "SPAKE2+-P256-SHA256-HKDF draft-01", + .context = reinterpret_cast("SPAKE2+-P256-SHA256-HKDF draft-01"), .context_len = 33, - .prover_identity = (const uint8_t *) "", + .prover_identity = reinterpret_cast(""), .prover_identity_len = 0, - .verifier_identity = (const uint8_t *) "server", + .verifier_identity = reinterpret_cast("server"), .verifier_identity_len = 6, .w0 = chiptest_e4836c3b50dd_w0_33, .w0_len = 32, @@ -399,11 +399,11 @@ static const uint8_t chiptest_e4836c3b50dd_MAC_KcB_63[] = { 0x09, 0x5d, 0xc0, 0x 0x37, 0x81, 0x18, 0x15, 0xb3, 0xc1, 0x52, 0x4a, 0xae, 0x80, 0xfd, 0x4e, 0x68, 0x10, 0xcf, 0x53, 0x1c, 0xf1, 0x1d, 0x20, 0xe3 }; static const struct spake2p_rfc_tv chiptest_e4836c3b50dd_test_vector_64 = { - .context = (const uint8_t *) "SPAKE2+-P256-SHA256-HKDF draft-01", + .context = reinterpret_cast("SPAKE2+-P256-SHA256-HKDF draft-01"), .context_len = 33, - .prover_identity = (const uint8_t *) "", + .prover_identity = reinterpret_cast(""), .prover_identity_len = 0, - .verifier_identity = (const uint8_t *) "", + .verifier_identity = reinterpret_cast(""), .verifier_identity_len = 0, .w0 = chiptest_e4836c3b50dd_w0_49, .w0_len = 32, diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index dd5ca51fd2229f..c5a7438f0475a4 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -145,14 +145,14 @@ extern template class Internal::GenericConfigurationManagerImpl inline CHIP_ERROR GenericConfigurationManagerImpl::_GetVendorId(uint16_t & vendorId) { - vendorId = (uint16_t) CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID; + vendorId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID); return CHIP_NO_ERROR; } template inline CHIP_ERROR GenericConfigurationManagerImpl::_GetProductId(uint16_t & productId) { - productId = (uint16_t) CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID; + productId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID); return CHIP_NO_ERROR; } diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index f8bb14a4855978..55fdf44ae3afda 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -246,12 +246,12 @@ inline CHIP_ERROR GenericConfigurationManagerImpl::_GetProductRevisio err = Impl()->ReadConfigValue(ImplClass::kConfigKey_ProductRevision, val); if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) { - productRev = (uint16_t) CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION; + productRev = static_cast(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION); err = CHIP_NO_ERROR; } else { - productRev = (uint16_t) val; + productRev = static_cast(val); } return err; @@ -260,7 +260,7 @@ inline CHIP_ERROR GenericConfigurationManagerImpl::_GetProductRevisio template inline CHIP_ERROR GenericConfigurationManagerImpl::_StoreProductRevision(uint16_t productRev) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_ProductRevision, (uint32_t) productRev); + return Impl()->WriteConfigValue(ImplClass::kConfigKey_ProductRevision, static_cast(productRev)); } template @@ -592,7 +592,7 @@ CHIP_ERROR GenericConfigurationManagerImpl::_GetSetupDiscriminator(ui #endif // defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR SuccessOrExit(err); - setupDiscriminator = (uint16_t) val; + setupDiscriminator = static_cast(val); exit: return err; @@ -601,7 +601,7 @@ exit: template CHIP_ERROR GenericConfigurationManagerImpl::_StoreSetupDiscriminator(uint16_t setupDiscriminator) { - return Impl()->WriteConfigValue(ImplClass::kConfigKey_SetupDiscriminator, (uint32_t) setupDiscriminator); + return Impl()->WriteConfigValue(ImplClass::kConfigKey_SetupDiscriminator, static_cast(setupDiscriminator)); } template diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.ipp b/src/include/platform/internal/GenericPlatformManagerImpl.ipp index e821090c9f0273..1851c864fd56bd 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.ipp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.ipp @@ -210,7 +210,7 @@ void GenericPlatformManagerImpl::_DispatchEvent(const ChipDeviceEvent // TODO: make this configurable #if CHIP_PROGRESS_LOGGING - uint32_t delta = ((uint32_t)(System::Layer::GetClock_MonotonicHiRes() - startUS)) / 1000; + uint32_t delta = (static_cast(System::Layer::GetClock_MonotonicHiRes() - startUS)) / 1000; if (delta > 100) { ChipLogError(DeviceLayer, "Long dispatch time: %" PRId32 " ms", delta); diff --git a/src/inet/DNSResolver.cpp b/src/inet/DNSResolver.cpp index 213cb61e2c8244..b2175320bc8243 100644 --- a/src/inet/DNSResolver.cpp +++ b/src/inet/DNSResolver.cpp @@ -427,7 +427,7 @@ INET_ERROR DNSResolver::ProcessGetAddrInfoResult(int returnCode, struct addrinfo // when attempting to communicate with the host. if (numAddrs > MaxAddrs && MaxAddrs > 1 && numPrimaryAddrs > 0 && numSecondaryAddrs > 0) { - numPrimaryAddrs = ::chip::min(numPrimaryAddrs, (uint8_t)(MaxAddrs - 1)); + numPrimaryAddrs = ::chip::min(numPrimaryAddrs, static_cast(MaxAddrs - 1)); } // Copy the primary addresses into the beginning of the application's output array, diff --git a/src/inet/IPAddress-StringFuncts.cpp b/src/inet/IPAddress-StringFuncts.cpp index 68cfd3ab15a2b9..b90d125546fb6b 100644 --- a/src/inet/IPAddress-StringFuncts.cpp +++ b/src/inet/IPAddress-StringFuncts.cpp @@ -69,12 +69,12 @@ char * IPAddress::ToString(char * buf, uint32_t bufSize) const #if INET_CONFIG_ENABLE_IPV4 if (IsIPv4()) { - buf = (char *) inet_ntop(AF_INET, (const void *) &Addr[3], buf, static_cast(bufSize)); + buf = const_cast(inet_ntop(AF_INET, (const void *) &Addr[3], buf, static_cast(bufSize))); } else #endif // INET_CONFIG_ENABLE_IPV4 { - buf = (char *) inet_ntop(AF_INET6, (const void *) Addr, buf, static_cast(bufSize)); + buf = const_cast(inet_ntop(AF_INET6, (const void *) Addr, buf, static_cast(bufSize))); } #endif // !CHIP_SYSTEM_CONFIG_USE_LWIP diff --git a/src/inet/IPAddress.cpp b/src/inet/IPAddress.cpp index 97d0019f93c1df..5ba968d9874db6 100644 --- a/src/inet/IPAddress.cpp +++ b/src/inet/IPAddress.cpp @@ -209,14 +209,15 @@ struct in6_addr IPAddress::ToIPv6() const IPAddress IPAddress::FromIPv6(const struct in6_addr & ipv6Addr) { IPAddress ipAddr; - ipAddr.Addr[0] = htonl(((uint32_t) ipv6Addr.s6_addr[0]) << 24 | ((uint32_t) ipv6Addr.s6_addr[1]) << 16 | - ((uint32_t) ipv6Addr.s6_addr[2]) << 8 | ((uint32_t) ipv6Addr.s6_addr[3])); - ipAddr.Addr[1] = htonl(((uint32_t) ipv6Addr.s6_addr[4]) << 24 | ((uint32_t) ipv6Addr.s6_addr[5]) << 16 | - ((uint32_t) ipv6Addr.s6_addr[6]) << 8 | ((uint32_t) ipv6Addr.s6_addr[7])); - ipAddr.Addr[2] = htonl(((uint32_t) ipv6Addr.s6_addr[8]) << 24 | ((uint32_t) ipv6Addr.s6_addr[9]) << 16 | - ((uint32_t) ipv6Addr.s6_addr[10]) << 8 | ((uint32_t) ipv6Addr.s6_addr[11])); - ipAddr.Addr[3] = htonl(((uint32_t) ipv6Addr.s6_addr[12]) << 24 | ((uint32_t) ipv6Addr.s6_addr[13]) << 16 | - ((uint32_t) ipv6Addr.s6_addr[14]) << 8 | ((uint32_t) ipv6Addr.s6_addr[15])); + ipAddr.Addr[0] = htonl((static_cast(ipv6Addr.s6_addr[0])) << 24 | (static_cast(ipv6Addr.s6_addr[1])) << 16 | + (static_cast(ipv6Addr.s6_addr[2])) << 8 | (static_cast(ipv6Addr.s6_addr[3]))); + ipAddr.Addr[1] = htonl((static_cast(ipv6Addr.s6_addr[4])) << 24 | (static_cast(ipv6Addr.s6_addr[5])) << 16 | + (static_cast(ipv6Addr.s6_addr[6])) << 8 | (static_cast(ipv6Addr.s6_addr[7]))); + ipAddr.Addr[2] = htonl((static_cast(ipv6Addr.s6_addr[8])) << 24 | (static_cast(ipv6Addr.s6_addr[9])) << 16 | + (static_cast(ipv6Addr.s6_addr[10])) << 8 | (static_cast(ipv6Addr.s6_addr[11]))); + ipAddr.Addr[3] = + htonl((static_cast(ipv6Addr.s6_addr[12])) << 24 | (static_cast(ipv6Addr.s6_addr[13])) << 16 | + (static_cast(ipv6Addr.s6_addr[14])) << 8 | (static_cast(ipv6Addr.s6_addr[15]))); return ipAddr; } @@ -291,7 +292,7 @@ bool IPAddress::IsIPv6LinkLocal() const uint64_t IPAddress::InterfaceId() const { if (IsIPv6ULA()) - return (((uint64_t) ntohl(Addr[2])) << 32) | ((uint64_t) ntohl(Addr[3])); + return ((static_cast(ntohl(Addr[2]))) << 32) | (static_cast(ntohl(Addr[3]))); return 0; } @@ -300,7 +301,7 @@ uint64_t IPAddress::InterfaceId() const uint16_t IPAddress::Subnet() const { if (IsIPv6ULA()) - return (uint16_t) ntohl(Addr[1]); + return static_cast(ntohl(Addr[1])); return 0; } @@ -309,7 +310,8 @@ uint16_t IPAddress::Subnet() const uint64_t IPAddress::GlobalId() const { if (IsIPv6ULA()) - return (((uint64_t)(ntohl(Addr[0]) & 0xFFFFFF)) << 16) | ((uint64_t)(ntohl(Addr[1])) & 0xFFFF0000) >> 16; + return ((static_cast(ntohl(Addr[0]) & 0xFFFFFF)) << 16) | + (static_cast(ntohl(Addr[1])) & 0xFFFF0000) >> 16; return 0; } @@ -352,14 +354,14 @@ IPAddress IPAddress::MakeULA(uint64_t globalId, uint16_t subnet, uint64_t interf { IPAddress addr; - addr.Addr[0] = 0xFD000000 | (uint32_t)((globalId & 0xFFFFFF0000ULL) >> 16); + addr.Addr[0] = 0xFD000000 | static_cast((globalId & 0xFFFFFF0000ULL) >> 16); addr.Addr[0] = htonl(addr.Addr[0]); - addr.Addr[1] = (uint32_t)((globalId & 0x000000FFFFULL) << 16) | subnet; + addr.Addr[1] = static_cast((globalId & 0x000000FFFFULL) << 16) | subnet; addr.Addr[1] = htonl(addr.Addr[1]); - addr.Addr[2] = htonl((uint32_t)(interfaceId >> 32)); - addr.Addr[3] = htonl((uint32_t)(interfaceId)); + addr.Addr[2] = htonl(static_cast(interfaceId >> 32)); + addr.Addr[3] = htonl(static_cast(interfaceId)); return addr; } @@ -371,8 +373,8 @@ IPAddress IPAddress::MakeLLA(uint64_t interfaceId) addr.Addr[0] = htonl(0xFE800000); addr.Addr[1] = 0; - addr.Addr[2] = htonl((uint32_t)(interfaceId >> 32)); - addr.Addr[3] = htonl((uint32_t)(interfaceId)); + addr.Addr[2] = htonl(static_cast(interfaceId >> 32)); + addr.Addr[3] = htonl(static_cast(interfaceId)); return addr; } @@ -406,10 +408,10 @@ IPAddress IPAddress::MakeIPv6Multicast(uint8_t aFlags, uint8_t aScope, uint32_t 0, 0, 0, - (uint8_t)((aGroupId & 0xFF000000U) >> 24), - (uint8_t)((aGroupId & 0x00FF0000U) >> 16), - (uint8_t)((aGroupId & 0x0000FF00U) >> 8), - (uint8_t)((aGroupId & 0x000000FFU) >> 0) }; + static_cast((aGroupId & 0xFF000000U) >> 24), + static_cast((aGroupId & 0x00FF0000U) >> 16), + static_cast((aGroupId & 0x0000FF00U) >> 8), + static_cast((aGroupId & 0x000000FFU) >> 0) }; return (MakeIPv6Multicast(aFlags, aScope, lGroupId)); } @@ -435,18 +437,18 @@ IPAddress IPAddress::MakeIPv6PrefixMulticast(uint8_t aScope, uint8_t aPrefixLeng const uint8_t lFlags = kIPv6MulticastFlag_Prefix; const uint8_t lGroupId[NL_INET_IPV6_MCAST_GROUP_LEN_IN_BYTES] = { lReserved, aPrefixLength, - (uint8_t)((aPrefix & 0xFF00000000000000ULL) >> 56), - (uint8_t)((aPrefix & 0x00FF000000000000ULL) >> 48), - (uint8_t)((aPrefix & 0x0000FF0000000000ULL) >> 40), - (uint8_t)((aPrefix & 0x000000FF00000000ULL) >> 32), - (uint8_t)((aPrefix & 0x00000000FF000000ULL) >> 24), - (uint8_t)((aPrefix & 0x0000000000FF0000ULL) >> 16), - (uint8_t)((aPrefix & 0x000000000000FF00ULL) >> 8), - (uint8_t)((aPrefix & 0x00000000000000FFULL) >> 0), - (uint8_t)((aGroupId & 0xFF000000U) >> 24), - (uint8_t)((aGroupId & 0x00FF0000U) >> 16), - (uint8_t)((aGroupId & 0x0000FF00U) >> 8), - (uint8_t)((aGroupId & 0x000000FFU) >> 0) }; + static_cast((aPrefix & 0xFF00000000000000ULL) >> 56), + static_cast((aPrefix & 0x00FF000000000000ULL) >> 48), + static_cast((aPrefix & 0x0000FF0000000000ULL) >> 40), + static_cast((aPrefix & 0x000000FF00000000ULL) >> 32), + static_cast((aPrefix & 0x00000000FF000000ULL) >> 24), + static_cast((aPrefix & 0x0000000000FF0000ULL) >> 16), + static_cast((aPrefix & 0x000000000000FF00ULL) >> 8), + static_cast((aPrefix & 0x00000000000000FFULL) >> 0), + static_cast((aGroupId & 0xFF000000U) >> 24), + static_cast((aGroupId & 0x00FF0000U) >> 16), + static_cast((aGroupId & 0x0000FF00U) >> 8), + static_cast((aGroupId & 0x000000FFU) >> 0) }; return (MakeIPv6TransientMulticast(lFlags, aScope, lGroupId)); } diff --git a/src/inet/IPEndPointBasis.cpp b/src/inet/IPEndPointBasis.cpp index 2334a6ccef580d..52b0f52f3e8026 100644 --- a/src/inet/IPEndPointBasis.cpp +++ b/src/inet/IPEndPointBasis.cpp @@ -700,7 +700,7 @@ INET_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, IPAddress aAddress, } sa.sin6_scope_id = static_cast(aInterfaceId); - if (bind(mSocket, (const sockaddr *) &sa, (unsigned) sizeof(sa)) != 0) + if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) lRetval = chip::System::MapErrorPOSIX(errno); // Instruct the kernel that any messages to multicast destinations should be @@ -729,7 +729,7 @@ INET_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, IPAddress aAddress, sa.sin_port = htons(aPort); sa.sin_addr = aAddress.ToIPv4(); - if (bind(mSocket, (const sockaddr *) &sa, (unsigned) sizeof(sa)) != 0) + if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) lRetval = chip::System::MapErrorPOSIX(errno); // Instruct the kernel that any messages to multicast destinations should be @@ -872,7 +872,7 @@ INET_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: controlHdr->cmsg_type = IP_PKTINFO; controlHdr->cmsg_len = CMSG_LEN(sizeof(in_pktinfo)); - struct in_pktinfo * pktInfo = (struct in_pktinfo *) CMSG_DATA(controlHdr); + struct in_pktinfo * pktInfo = reinterpret_cast CMSG_DATA(controlHdr); if (!CanCastToipi_ifindex)>(intfId)) { ExitNow(res = INET_ERROR_NOT_SUPPORTED); @@ -896,7 +896,7 @@ INET_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: controlHdr->cmsg_type = IPV6_PKTINFO; controlHdr->cmsg_len = CMSG_LEN(sizeof(in6_pktinfo)); - struct in6_pktinfo * pktInfo = (struct in6_pktinfo *) CMSG_DATA(controlHdr); + struct in6_pktinfo * pktInfo = reinterpret_cast CMSG_DATA(controlHdr); if (!CanCastToipi6_ifindex)>(intfId)) { ExitNow(res = INET_ERROR_UNEXPECTED_EVENT); @@ -1095,7 +1095,7 @@ void IPEndPointBasis::HandlePendingIO(uint16_t aPort) } else { - lBuffer->SetDataLength((uint16_t) rcvLen); + lBuffer->SetDataLength(static_cast(rcvLen)); if (lPeerSockAddr.any.sa_family == AF_INET6) { @@ -1124,7 +1124,7 @@ void IPEndPointBasis::HandlePendingIO(uint16_t aPort) #ifdef IP_PKTINFO if (controlHdr->cmsg_level == IPPROTO_IP && controlHdr->cmsg_type == IP_PKTINFO) { - struct in_pktinfo * inPktInfo = (struct in_pktinfo *) CMSG_DATA(controlHdr); + struct in_pktinfo * inPktInfo = reinterpret_cast CMSG_DATA(controlHdr); if (!CanCastTo(inPktInfo->ipi_ifindex)) { lStatus = INET_ERROR_INCORRECT_STATE; @@ -1140,7 +1140,7 @@ void IPEndPointBasis::HandlePendingIO(uint16_t aPort) #ifdef IPV6_PKTINFO if (controlHdr->cmsg_level == IPPROTO_IPV6 && controlHdr->cmsg_type == IPV6_PKTINFO) { - struct in6_pktinfo * in6PktInfo = (struct in6_pktinfo *) CMSG_DATA(controlHdr); + struct in6_pktinfo * in6PktInfo = reinterpret_cast CMSG_DATA(controlHdr); if (!CanCastTo(in6PktInfo->ipi6_ifindex)) { lStatus = INET_ERROR_INCORRECT_STATE; diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index 175531f7db0c76..d4049cd29d91af 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -925,13 +925,13 @@ uint8_t InterfaceAddressIterator::GetPrefixLength() #if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS if (mCurAddr->ifa_addr->sa_family == AF_INET6) { - struct sockaddr_in6 & netmask = *(struct sockaddr_in6 *) (mCurAddr->ifa_netmask); + struct sockaddr_in6 & netmask = *reinterpret_cast(mCurAddr->ifa_netmask); return NetmaskToPrefixLength(netmask.sin6_addr.s6_addr, 16); } if (mCurAddr->ifa_addr->sa_family == AF_INET) { - struct sockaddr_in & netmask = *(struct sockaddr_in *) (mCurAddr->ifa_netmask); - return NetmaskToPrefixLength((const uint8_t *) &netmask.sin_addr.s_addr, 4); + struct sockaddr_in & netmask = *reinterpret_cast(mCurAddr->ifa_netmask); + return NetmaskToPrefixLength(reinterpret_cast(&netmask.sin_addr.s_addr), 4); } #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp index e01d661cd50785..631d89faa24929 100644 --- a/src/inet/InetLayer.cpp +++ b/src/inet/InetLayer.cpp @@ -495,10 +495,11 @@ INET_ERROR InetLayer::GetLinkLocalAddr(InterfaceId link, IPAddress * llAddr) if ((ifaddr_iter->ifa_addr->sa_family == AF_INET6) && ((link == INET_NULL_INTERFACEID) || (if_nametoindex(ifaddr_iter->ifa_name) == link))) { - struct in6_addr * sin6_addr = &((struct sockaddr_in6 *) ifaddr_iter->ifa_addr)->sin6_addr; + struct in6_addr * sin6_addr = &(reinterpret_cast(ifaddr_iter->ifa_addr))->sin6_addr; if (sin6_addr->s6_addr[0] == 0xfe && (sin6_addr->s6_addr[1] & 0xc0) == 0x80) // Link Local Address { - (*llAddr) = IPAddress::FromIPv6(((struct sockaddr_in6 *) ifaddr_iter->ifa_addr)->sin6_addr); + (*llAddr) = + IPAddress::FromIPv6((reinterpret_cast(ifaddr_iter->ifa_addr))->sin6_addr); break; } } diff --git a/src/inet/InetUtils.cpp b/src/inet/InetUtils.cpp index 1bb55ddfbc9371..02d7468d3148f2 100644 --- a/src/inet/InetUtils.cpp +++ b/src/inet/InetUtils.cpp @@ -81,7 +81,7 @@ DLL_EXPORT INET_ERROR ParseHostAndPort(const char * aString, uint16_t aStringLen if (*aString == '[') { // Search for the end bracket. - p = (const char *) memchr(aString, ']', aStringLen); + p = static_cast(memchr(aString, ']', aStringLen)); if (p == nullptr) return INET_ERROR_INVALID_HOST_NAME; @@ -100,7 +100,7 @@ DLL_EXPORT INET_ERROR ParseHostAndPort(const char * aString, uint16_t aStringLen else { // Search for a colon. - p = (const char *) memchr(aString, ':', aStringLen); + p = static_cast(memchr(aString, ':', aStringLen)); // If the string contains no colons, then it is a host name or // IPv4 address without a port. diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp index 21a5079d8658ee..0ec5234b809c9c 100644 --- a/src/inet/TCPEndPoint.cpp +++ b/src/inet/TCPEndPoint.cpp @@ -223,7 +223,7 @@ INET_ERROR TCPEndPoint::Bind(IPAddressType addrType, IPAddress addr, uint16_t po sa.sin6_addr = addr.ToIPv6(); sa.sin6_scope_id = 0; - if (bind(mSocket, (const sockaddr *) &sa, (unsigned) sizeof(sa)) != 0) + if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) res = chip::System::MapErrorPOSIX(errno); } #if INET_CONFIG_ENABLE_IPV4 @@ -235,7 +235,7 @@ INET_ERROR TCPEndPoint::Bind(IPAddressType addrType, IPAddress addr, uint16_t po sa.sin_port = htons(port); sa.sin_addr = addr.ToIPv4(); - if (bind(mSocket, (const sockaddr *) &sa, (unsigned) sizeof(sa)) != 0) + if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) res = chip::System::MapErrorPOSIX(errno); } #endif // INET_CONFIG_ENABLE_IPV4 @@ -463,7 +463,7 @@ INET_ERROR TCPEndPoint::Connect(IPAddress addr, uint16_t port, InterfaceId intfI sa.in6.sin6_addr = addr.ToIPv6(); sa.in6.sin6_scope_id = intfId; sockaddrsize = sizeof(sockaddr_in6); - sockaddrptr = (const sockaddr *) &sa.in6; + sockaddrptr = reinterpret_cast(&sa.in6); } #if INET_CONFIG_ENABLE_IPV4 else if (addrType == kIPAddressType_IPv4) @@ -472,7 +472,7 @@ INET_ERROR TCPEndPoint::Connect(IPAddress addr, uint16_t port, InterfaceId intfI sa.in.sin_port = htons(port); sa.in.sin_addr = addr.ToIPv4(); sockaddrsize = sizeof(sockaddr_in); - sockaddrptr = (const sockaddr *) &sa.in; + sockaddrptr = reinterpret_cast(&sa.in); } #endif // INET_CONFIG_ENABLE_IPV4 else diff --git a/src/inet/tests/TestInetAddress.cpp b/src/inet/tests/TestInetAddress.cpp index 624739220d12e5..3d769267063604 100644 --- a/src/inet/tests/TestInetAddress.cpp +++ b/src/inet/tests/TestInetAddress.cpp @@ -1016,7 +1016,7 @@ void CheckToIPv6(nlTestSuite * inSuite, void * inContext) ip_addr_1 = *(ip6_addr_t *) addr; #else struct in6_addr ip_addr_1, ip_addr_2; - ip_addr_1 = *(struct in6_addr *) addr; + ip_addr_1 = *reinterpret_cast(addr); #endif ip_addr_2 = test_addr.ToIPv6(); @@ -1053,7 +1053,7 @@ void CheckFromIPv6(nlTestSuite * inSuite, void * inContext) ip_addr = *(ip6_addr_t *) addr; #else struct in6_addr ip_addr; - ip_addr = *(struct in6_addr *) addr; + ip_addr = *reinterpret_cast(addr); #endif test_addr_2 = IPAddress::FromIPv6(ip_addr); @@ -1428,7 +1428,7 @@ void CheckDecoding(nlTestSuite * inSuite, void * inContext) for (b = 0; b < NUM_BYTES_IN_IPV6; b++) { - buffer[b] = (uint8_t)(lCurrent->mAddr.mAddrQuartets[b / 4] >> ((3 - b % 4) * 8)); + buffer[b] = static_cast(lCurrent->mAddr.mAddrQuartets[b / 4] >> ((3 - b % 4) * 8)); } // Call ReadAddress function that we test. diff --git a/src/inet/tests/TestInetCommon.cpp b/src/inet/tests/TestInetCommon.cpp index c9b1cb462a68f6..b6e0335e2821fa 100644 --- a/src/inet/tests/TestInetCommon.cpp +++ b/src/inet/tests/TestInetCommon.cpp @@ -644,7 +644,7 @@ void DumpMemory(const uint8_t * mem, uint32_t len, const char * prefix, uint32_t printf(" "); for (j = i; j < rowEnd && j < len; j++) - if (isprint((char) mem[j])) + if (isprint(static_cast(mem[j]))) printf("%c", mem[j]); else printf("."); diff --git a/src/lib/core/CHIPTLVDebug.cpp b/src/lib/core/CHIPTLVDebug.cpp index 5ac8d64b5f1321..21015d90009fb7 100644 --- a/src/lib/core/CHIPTLVDebug.cpp +++ b/src/lib/core/CHIPTLVDebug.cpp @@ -82,7 +82,7 @@ static void DumpHandler(DumpWriter aWriter, const char * aIndent, const TLVReade } else if (IsContextTag(tag)) { - aWriter("tag[%s]: 0x%x, ", DecodeTagControl(tagControl), (uint32_t) ContextTag(tag)); + aWriter("tag[%s]: 0x%x, ", DecodeTagControl(tagControl), static_cast(ContextTag(tag))); } else if (IsSpecialTag(tag)) { diff --git a/src/lib/core/CHIPTLVReader.cpp b/src/lib/core/CHIPTLVReader.cpp index 826b073b0bf5c4..1b097cfc4c7790 100644 --- a/src/lib/core/CHIPTLVReader.cpp +++ b/src/lib/core/CHIPTLVReader.cpp @@ -269,8 +269,8 @@ TLVType TLVReader::GetType() const if (elemType == kTLVElementType_FloatingPointNumber32 || elemType == kTLVElementType_FloatingPointNumber64) return kTLVType_FloatingPointNumber; if (elemType == kTLVElementType_NotSpecified || elemType >= kTLVElementType_Null) - return (TLVType) elemType; - return (TLVType)(elemType & ~kTLVTypeSizeMask); + return static_cast(elemType); + return static_cast(elemType & ~kTLVTypeSizeMask); } /** @@ -327,7 +327,7 @@ uint64_t TLVReader::GetTag() const uint32_t TLVReader::GetLength() const { if (TLVTypeHasLength(ElementType())) - return (uint32_t) mElemLenOrVal; + return static_cast(mElemLenOrVal); return 0; } @@ -520,13 +520,13 @@ CHIP_ERROR TLVReader::Get(uint64_t & v) switch (ElementType()) { case kTLVElementType_Int8: - v = (int64_t)(int8_t) mElemLenOrVal; + v = static_cast(static_cast(mElemLenOrVal)); break; case kTLVElementType_Int16: - v = (int64_t)(int16_t) mElemLenOrVal; + v = static_cast(static_cast(mElemLenOrVal)); break; case kTLVElementType_Int32: - v = (int64_t)(int32_t) mElemLenOrVal; + v = static_cast(static_cast(mElemLenOrVal)); break; case kTLVElementType_Int64: case kTLVElementType_UInt8: @@ -561,7 +561,7 @@ CHIP_ERROR TLVReader::Get(double & v) uint32_t u32; float f; } cvt; - cvt.u32 = (uint32_t) mElemLenOrVal; + cvt.u32 = static_cast(mElemLenOrVal); v = cvt.f; break; } @@ -611,7 +611,7 @@ CHIP_ERROR TLVReader::GetBytes(uint8_t * buf, uint32_t bufSize) if (mElemLenOrVal > bufSize) return CHIP_ERROR_BUFFER_TOO_SMALL; - CHIP_ERROR err = ReadData(buf, (uint32_t) mElemLenOrVal); + CHIP_ERROR err = ReadData(buf, static_cast(mElemLenOrVal)); if (err != CHIP_NO_ERROR) return err; @@ -652,7 +652,7 @@ CHIP_ERROR TLVReader::GetString(char * buf, uint32_t bufSize) buf[mElemLenOrVal] = 0; - return GetBytes((uint8_t *) buf, bufSize - 1); + return GetBytes(reinterpret_cast(buf), bufSize - 1); } /** @@ -687,11 +687,11 @@ CHIP_ERROR TLVReader::DupBytes(uint8_t *& buf, uint32_t & dataLen) if (!TLVTypeIsString(ElementType())) return CHIP_ERROR_WRONG_TLV_TYPE; - buf = (uint8_t *) malloc(mElemLenOrVal); + buf = static_cast(malloc(mElemLenOrVal)); if (buf == nullptr) return CHIP_ERROR_NO_MEMORY; - CHIP_ERROR err = ReadData(buf, (uint32_t) mElemLenOrVal); + CHIP_ERROR err = ReadData(buf, static_cast(mElemLenOrVal)); if (err != CHIP_NO_ERROR) { free(buf); @@ -736,11 +736,11 @@ CHIP_ERROR TLVReader::DupString(char *& buf) if (!TLVTypeIsString(ElementType())) return CHIP_ERROR_WRONG_TLV_TYPE; - buf = (char *) malloc(mElemLenOrVal + 1); + buf = static_cast(malloc(mElemLenOrVal + 1)); if (buf == nullptr) return CHIP_ERROR_NO_MEMORY; - CHIP_ERROR err = ReadData((uint8_t *) buf, (uint32_t) mElemLenOrVal); + CHIP_ERROR err = ReadData(reinterpret_cast(buf), static_cast(mElemLenOrVal)); if (err != CHIP_NO_ERROR) { free(buf); @@ -793,7 +793,7 @@ CHIP_ERROR TLVReader::GetDataPtr(const uint8_t *& data) // Verify that the entirety of the data is available in the buffer. // Note that this may not be possible if the reader is reading from a chain of buffers. - if (remainingLen < (uint32_t) mElemLenOrVal) + if (remainingLen < static_cast(mElemLenOrVal)) return CHIP_ERROR_TLV_UNDERRUN; data = mReadPoint; @@ -851,7 +851,7 @@ CHIP_ERROR TLVReader::OpenContainer(TLVReader & containerReader) containerReader.mLenRead = mLenRead; containerReader.mMaxLen = mMaxLen; containerReader.ClearElementState(); - containerReader.mContainerType = (TLVType) elemType; + containerReader.mContainerType = static_cast(elemType); containerReader.SetContainerOpen(false); containerReader.ImplicitProfileId = ImplicitProfileId; containerReader.AppData = AppData; @@ -902,7 +902,7 @@ CHIP_ERROR TLVReader::CloseContainer(TLVReader & containerReader) if (!IsContainerOpen()) return CHIP_ERROR_INCORRECT_STATE; - if ((TLVElementType) containerReader.mContainerType != ElementType()) + if (static_cast(containerReader.mContainerType) != ElementType()) return CHIP_ERROR_INCORRECT_STATE; err = containerReader.SkipToEndOfContainer(); @@ -951,7 +951,7 @@ CHIP_ERROR TLVReader::EnterContainer(TLVType & outerContainerType) return CHIP_ERROR_INCORRECT_STATE; outerContainerType = mContainerType; - mContainerType = (TLVType) elemType; + mContainerType = static_cast(elemType); ClearElementState(); SetContainerOpen(false); @@ -1266,7 +1266,7 @@ CHIP_ERROR TLVReader::SkipToEndOfContainer() else if (TLVTypeIsContainer(elemType)) { nestLevel++; - mContainerType = (TLVType) elemType; + mContainerType = static_cast(elemType); } err = SkipData(); @@ -1300,7 +1300,7 @@ CHIP_ERROR TLVReader::ReadElement() return CHIP_ERROR_INVALID_TLV_ELEMENT; // Extract the tag control from the control byte. - TLVTagControl tagControl = (TLVTagControl)(mControlByte & kTLVTagControlMask); + TLVTagControl tagControl = static_cast(mControlByte & kTLVTagControlMask); // Determine the number of bytes in the element's tag, if any. uint8_t tagBytes = sTagSizes[tagControl >> kTLVTagControlShift]; @@ -1406,7 +1406,7 @@ CHIP_ERROR TLVReader::VerifyElement() if (TLVTypeHasLength(ElementType())) { uint32_t overallLenRemaining = mMaxLen - mLenRead; - if (overallLenRemaining < (uint32_t) mElemLenOrVal) + if (overallLenRemaining < static_cast(mElemLenOrVal)) return CHIP_ERROR_TLV_UNDERRUN; } @@ -1524,7 +1524,7 @@ CHIP_ERROR TLVReader::GetElementHeadLength(uint8_t & elemHeadBytes) const VerifyOrExit(IsValidTLVType(elemType), err = CHIP_ERROR_INVALID_TLV_ELEMENT); // Extract the tag control from the control byte. - tagControl = (TLVTagControl)(mControlByte & kTLVTagControlMask); + tagControl = static_cast(mControlByte & kTLVTagControlMask); // Determine the number of bytes in the element's tag, if any. tagBytes = sTagSizes[tagControl >> kTLVTagControlShift]; @@ -1550,9 +1550,9 @@ CHIP_ERROR TLVReader::GetElementHeadLength(uint8_t & elemHeadBytes) const */ TLVElementType TLVReader::ElementType() const { - if (mControlByte == (uint16_t) kTLVControlByte_NotSpecified) + if (mControlByte == static_cast(kTLVControlByte_NotSpecified)) return kTLVElementType_NotSpecified; - return (TLVElementType)(mControlByte & kTLVTypeMask); + return static_cast(mControlByte & kTLVTypeMask); } CHIP_ERROR TLVReader::GetNextPacketBuffer(TLVReader & reader, uintptr_t & bufHandle, const uint8_t *& bufStart, uint32_t & bufLen) diff --git a/src/lib/core/CHIPTLVTags.h b/src/lib/core/CHIPTLVTags.h index 79055b706adab3..fa5f44507b47fd 100644 --- a/src/lib/core/CHIPTLVTags.h +++ b/src/lib/core/CHIPTLVTags.h @@ -81,7 +81,7 @@ enum */ inline uint64_t ProfileTag(uint32_t profileId, uint32_t tagNum) { - return (((uint64_t) profileId) << kProfileIdShift) | tagNum; + return ((static_cast(profileId)) << kProfileIdShift) | tagNum; } /** @@ -94,7 +94,8 @@ inline uint64_t ProfileTag(uint32_t profileId, uint32_t tagNum) */ inline uint64_t ProfileTag(uint16_t vendorId, uint16_t profileNum, uint32_t tagNum) { - return (((uint64_t) vendorId) << kVendorIdShift) | (((uint64_t) profileNum) << kProfileNumShift) | tagNum; + return ((static_cast(vendorId)) << kVendorIdShift) | ((static_cast(profileNum)) << kProfileNumShift) | + tagNum; } /** @@ -140,7 +141,7 @@ enum */ inline uint32_t ProfileIdFromTag(uint64_t tag) { - return (uint32_t)((tag & kProfileIdMask) >> kProfileIdShift); + return static_cast((tag & kProfileIdMask) >> kProfileIdShift); } /** @@ -153,7 +154,7 @@ inline uint32_t ProfileIdFromTag(uint64_t tag) */ inline uint16_t ProfileNumFromTag(uint64_t tag) { - return (uint16_t)((tag & kProfileIdMask) >> kProfileIdShift); + return static_cast((tag & kProfileIdMask) >> kProfileIdShift); } /** @@ -169,7 +170,7 @@ inline uint16_t ProfileNumFromTag(uint64_t tag) */ inline uint32_t TagNumFromTag(uint64_t tag) { - return (uint32_t)(tag & kTagNumMask); + return static_cast(tag & kTagNumMask); } /** @@ -182,7 +183,7 @@ inline uint32_t TagNumFromTag(uint64_t tag) */ inline uint16_t VendorIdFromTag(uint64_t tag) { - return (uint16_t)((tag & kProfileIdMask) >> kVendorIdShift); + return static_cast((tag & kProfileIdMask) >> kVendorIdShift); } /** diff --git a/src/lib/core/CHIPTLVTypes.h b/src/lib/core/CHIPTLVTypes.h index 8673b1e3525193..8ad94a6ef77360 100644 --- a/src/lib/core/CHIPTLVTypes.h +++ b/src/lib/core/CHIPTLVTypes.h @@ -151,7 +151,7 @@ inline bool TLVTypeIsString(uint8_t type) inline TLVFieldSize GetTLVFieldSize(uint8_t type) { if (TLVTypeHasValue(type)) - return (TLVFieldSize)(type & kTLVTypeSizeMask); + return static_cast(type & kTLVTypeSizeMask); return kTLVFieldSize_0Byte; } diff --git a/src/lib/core/CHIPTLVWriter.cpp b/src/lib/core/CHIPTLVWriter.cpp index 2a5d4342854d2d..d68361296ecd53 100644 --- a/src/lib/core/CHIPTLVWriter.cpp +++ b/src/lib/core/CHIPTLVWriter.cpp @@ -657,7 +657,7 @@ CHIP_ERROR TLVWriter::Put(uint64_t tag, double v) */ CHIP_ERROR TLVWriter::PutBytes(uint64_t tag, const uint8_t * buf, uint32_t len) { - return WriteElementWithData(kTLVType_ByteString, tag, (const uint8_t *) buf, len); + return WriteElementWithData(kTLVType_ByteString, tag, buf, len); } /** @@ -720,7 +720,7 @@ CHIP_ERROR TLVWriter::PutString(uint64_t tag, const char * buf) */ CHIP_ERROR TLVWriter::PutString(uint64_t tag, const char * buf, uint32_t len) { - return WriteElementWithData(kTLVType_UTF8String, tag, (const uint8_t *) buf, len); + return WriteElementWithData(kTLVType_UTF8String, tag, reinterpret_cast(buf), len); } /** @@ -883,7 +883,7 @@ CHIP_ERROR TLVWriter::VPutStringF(uint64_t tag, const char * fmt, va_list ap) #endif // write length. - err = WriteElementHead((TLVElementType)(kTLVType_UTF8String | lenFieldSize), tag, dataLen); + err = WriteElementHead(static_cast(kTLVType_UTF8String | lenFieldSize), tag, dataLen); SuccessOrExit(err); VerifyOrExit((mLenWritten + dataLen) <= mMaxLen, err = CHIP_ERROR_BUFFER_TOO_SMALL); @@ -1197,7 +1197,7 @@ CHIP_ERROR TLVWriter::OpenContainer(uint64_t tag, TLVType containerType, TLVWrit VerifyOrExit(mMaxLen >= kEndOfContainerMarkerSize, err = CHIP_ERROR_BUFFER_TOO_SMALL); mMaxLen -= kEndOfContainerMarkerSize; } - err = WriteElementHead((TLVElementType) containerType, tag, 0); + err = WriteElementHead(static_cast(containerType), tag, 0); if (err != CHIP_NO_ERROR) { @@ -1337,7 +1337,7 @@ CHIP_ERROR TLVWriter::StartContainer(uint64_t tag, TLVType containerType, TLVTyp mMaxLen -= kEndOfContainerMarkerSize; } - err = WriteElementHead((TLVElementType) containerType, tag, 0); + err = WriteElementHead(static_cast(containerType), tag, 0); if (err != CHIP_NO_ERROR) { // undo the space reservation, as the container is not actually open @@ -1447,7 +1447,7 @@ CHIP_ERROR TLVWriter::PutPreEncodedContainer(uint64_t tag, TLVType containerType if (!TLVTypeIsContainer(containerType)) return CHIP_ERROR_INVALID_ARGUMENT; - CHIP_ERROR err = WriteElementHead((TLVElementType) containerType, tag, 0); + CHIP_ERROR err = WriteElementHead(static_cast(containerType), tag, 0); if (err != CHIP_NO_ERROR) return err; @@ -1672,7 +1672,7 @@ CHIP_ERROR TLVWriter::WriteElementHead(TLVElementType elemType, uint64_t tag, ui return CHIP_ERROR_INVALID_TLV_TAG; Write8(p, kTLVTagControl_ContextSpecific | elemType); - Write8(p, (uint8_t) tagNum); + Write8(p, static_cast(tagNum)); } else { @@ -1695,7 +1695,7 @@ CHIP_ERROR TLVWriter::WriteElementHead(TLVElementType elemType, uint64_t tag, ui if (tagNum < 65536) { Write8(p, kTLVTagControl_CommonProfile_2Bytes | elemType); - LittleEndian::Write16(p, (uint16_t) tagNum); + LittleEndian::Write16(p, static_cast(tagNum)); } else { @@ -1708,7 +1708,7 @@ CHIP_ERROR TLVWriter::WriteElementHead(TLVElementType elemType, uint64_t tag, ui if (tagNum < 65536) { Write8(p, kTLVTagControl_ImplicitProfile_2Bytes | elemType); - LittleEndian::Write16(p, (uint16_t) tagNum); + LittleEndian::Write16(p, static_cast(tagNum)); } else { @@ -1718,15 +1718,15 @@ CHIP_ERROR TLVWriter::WriteElementHead(TLVElementType elemType, uint64_t tag, ui } else { - uint16_t vendorId = (uint16_t)(profileId >> 16); - uint16_t profileNum = (uint16_t) profileId; + uint16_t vendorId = static_cast(profileId >> 16); + uint16_t profileNum = static_cast(profileId); if (tagNum < 65536) { Write8(p, kTLVTagControl_FullyQualified_6Bytes | elemType); LittleEndian::Write16(p, vendorId); LittleEndian::Write16(p, profileNum); - LittleEndian::Write16(p, (uint16_t) tagNum); + LittleEndian::Write16(p, static_cast(tagNum)); } else { @@ -1743,13 +1743,13 @@ CHIP_ERROR TLVWriter::WriteElementHead(TLVElementType elemType, uint64_t tag, ui case kTLVFieldSize_0Byte: break; case kTLVFieldSize_1Byte: - Write8(p, (uint8_t) lenOrVal); + Write8(p, static_cast(lenOrVal)); break; case kTLVFieldSize_2Byte: - LittleEndian::Write16(p, (uint16_t) lenOrVal); + LittleEndian::Write16(p, static_cast(lenOrVal)); break; case kTLVFieldSize_4Byte: - LittleEndian::Write32(p, (uint32_t) lenOrVal); + LittleEndian::Write32(p, static_cast(lenOrVal)); break; case kTLVFieldSize_8Byte: LittleEndian::Write64(p, lenOrVal); @@ -1778,7 +1778,7 @@ CHIP_ERROR TLVWriter::WriteElementWithData(TLVType type, uint64_t tag, const uin else lenFieldSize = kTLVFieldSize_4Byte; - CHIP_ERROR err = WriteElementHead((TLVElementType)(type | lenFieldSize), tag, dataLen); + CHIP_ERROR err = WriteElementHead(static_cast(type | lenFieldSize), tag, dataLen); if (err != CHIP_NO_ERROR) return err; diff --git a/src/lib/core/tests/TestCHIPTLV.cpp b/src/lib/core/tests/TestCHIPTLV.cpp index 8b2ccb74852ea6..bbcdd985a8d5bc 100644 --- a/src/lib/core/tests/TestCHIPTLV.cpp +++ b/src/lib/core/tests/TestCHIPTLV.cpp @@ -211,7 +211,7 @@ void TestString(nlTestSuite * inSuite, TLVReader & reader, uint64_t tag, const c uint32_t expectedLen = strlen(expectedVal); NL_TEST_ASSERT(inSuite, reader.GetLength() == expectedLen); - char * val = (char *) malloc(expectedLen + 1); + char * val = static_cast(malloc(expectedLen + 1)); CHIP_ERROR err = reader.GetString(val, expectedLen + 1); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -229,7 +229,7 @@ void TestDupString(nlTestSuite * inSuite, TLVReader & reader, uint64_t tag, cons uint32_t expectedLen = strlen(expectedVal); NL_TEST_ASSERT(inSuite, reader.GetLength() == expectedLen); - char * val = (char *) malloc(expectedLen + 1); + char * val = static_cast(malloc(expectedLen + 1)); CHIP_ERROR err = reader.DupString(val); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -246,7 +246,7 @@ void TestDupBytes(nlTestSuite * inSuite, TLVReader & reader, uint64_t tag, const NL_TEST_ASSERT(inSuite, reader.GetLength() == expectedLen); - uint8_t * val = (uint8_t *) malloc(expectedLen); + uint8_t * val = static_cast(malloc(expectedLen)); CHIP_ERROR err = reader.DupBytes(val, expectedLen); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); @@ -435,10 +435,10 @@ void WriteEncoding1(nlTestSuite * inSuite, TLVWriter & writer) err = writer2.PutString(ProfileTag(TestProfile_1, 5), "This is a test"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer2.Put(ProfileTag(TestProfile_2, 65535), (float) 17.9); + err = writer2.Put(ProfileTag(TestProfile_2, 65535), static_cast(17.9)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer2.Put(ProfileTag(TestProfile_2, 65536), (double) 17.9); + err = writer2.Put(ProfileTag(TestProfile_2, 65536), 17.9); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); err = writer.CloseContainer(writer2); @@ -581,11 +581,12 @@ void ReadEncoding1(nlTestSuite * inSuite, TLVReader & reader) TestNext(inSuite, reader2); - TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), (float) 17.9); + TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), + static_cast(17.9)); TestNext(inSuite, reader2); - TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), (double) 17.9); + TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), 17.9); TestEndAndCloseContainer(inSuite, reader, reader2); } @@ -2636,13 +2637,13 @@ void PreserveSizeWrite(nlTestSuite * inSuite, TLVWriter & writer, bool preserveS TLVWriter writer2; // kTLVTagControl_FullyQualified_8Bytes - err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), (int64_t) 40000000000ULL, true); + err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), static_cast(40000000000ULL), true); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), (int16_t) 12345, true); + err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), static_cast(12345), true); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), (float) 1.0); + err = writer.Put(ProfileTag(TestProfile_1, 4000000000ULL), static_cast(1.0)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); err = writer.OpenContainer(ProfileTag(TestProfile_1, 1), kTLVType_Structure, writer2); @@ -2654,38 +2655,38 @@ void PreserveSizeWrite(nlTestSuite * inSuite, TLVWriter & writer, bool preserveS err = writer2.OpenContainer(ContextTag(0), kTLVType_Array, writer3); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (uint8_t) 42, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(42), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (uint16_t) 42, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(42), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (uint32_t) 42, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(42), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (uint64_t) 40000000000ULL, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(40000000000ULL), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (int8_t) -17, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(-17), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (int16_t) -17, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(-17), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (int32_t) -170000, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(-170000), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (int64_t) -170000, preserveSize); + err = writer3.Put(AnonymousTag, static_cast(-170000), preserveSize); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); // the below cases are for full coverage of PUTs - err = writer3.Put(AnonymousTag, (uint64_t) 65535, false); + err = writer3.Put(AnonymousTag, static_cast(65535), false); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (int64_t) 32767, false); + err = writer3.Put(AnonymousTag, static_cast(32767), false); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = writer3.Put(AnonymousTag, (int64_t) 40000000000ULL, false); + err = writer3.Put(AnonymousTag, static_cast(40000000000ULL), false); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); err = writer2.CloseContainer(writer3); @@ -2958,15 +2959,16 @@ void TestCHIPTLVReaderDup(nlTestSuite * inSuite) TestNext(inSuite, reader2); - TestDupBytes(inSuite, reader2, ProfileTag(TestProfile_1, 5), (uint8_t *) ("This is a test"), 14); + TestDupBytes(inSuite, reader2, ProfileTag(TestProfile_1, 5), reinterpret_cast("This is a test"), 14); TestNext(inSuite, reader2); - TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), (float) 17.9); + TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65535), + static_cast(17.9)); TestNext(inSuite, reader2); - TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), (double) 17.9); + TestGet(inSuite, reader2, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_2, 65536), 17.9); TestEndAndCloseContainer(inSuite, reader, reader2); } @@ -3025,13 +3027,13 @@ void TestCHIPTLVReaderErrorHandling(nlTestSuite * inSuite) NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_INCORRECT_STATE); // DupString() - char * str = (char *) malloc(16); + char * str = static_cast(malloc(16)); err = reader.DupString(str); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE); free(str); // GetDataPtr() - const uint8_t * data = (uint8_t *) malloc(16); + const uint8_t * data = static_cast(malloc(16)); err = reader.GetDataPtr(data); NL_TEST_ASSERT(inSuite, err == CHIP_ERROR_WRONG_TLV_TYPE); free((void *) data); @@ -3055,16 +3057,17 @@ void TestCHIPTLVReaderInPractice(nlTestSuite * inSuite) TestNext(inSuite, reader); TestGet(inSuite, reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL), - (int64_t) 40000000000ULL); + static_cast(40000000000ULL)); TestNext(inSuite, reader); - TestGet(inSuite, reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL), (int16_t) 12345); + TestGet(inSuite, reader, kTLVType_SignedInteger, ProfileTag(TestProfile_1, 4000000000ULL), + static_cast(12345)); TestNext(inSuite, reader); TestGet(inSuite, reader, kTLVType_FloatingPointNumber, ProfileTag(TestProfile_1, 4000000000ULL), - (float) 1.0); + static_cast(1.0)); } void TestCHIPTLVReader_NextOverContainer_ProcessElement(nlTestSuite * inSuite, TLVReader & reader, void * context) @@ -3760,8 +3763,8 @@ static void TLVReaderFuzzTest(nlTestSuite * inSuite, void * inContext) if (readRes == CHIP_NO_ERROR) { - printf("Unexpected success of fuzz test: offset %u, original value 0x%02X, mutated value 0x%02X\n", (unsigned) i, - (unsigned) origVal, (unsigned) fuzzedData[i]); + printf("Unexpected success of fuzz test: offset %u, original value 0x%02X, mutated value 0x%02X\n", + static_cast(i), static_cast(origVal), static_cast(fuzzedData[i])); ExitNow(); } diff --git a/src/lib/message/CHIPBinding.cpp b/src/lib/message/CHIPBinding.cpp index e6211c7a2e125f..463f753a5ac3d3 100644 --- a/src/lib/message/CHIPBinding.cpp +++ b/src/lib/message/CHIPBinding.cpp @@ -893,7 +893,7 @@ void Binding::HandleBindingFailed(CHIP_ERROR err, Protocols::StatusReporting::St */ void Binding::OnResolveComplete(void * appState, INET_ERROR err, uint8_t addrCount, IPAddress * addrArray) { - Binding * _this = (Binding *) appState; + Binding * _this = static_cast(appState); // It is legal for a DNS entry to exist but contain no A/AAAA records. If this happens, return a reasonable error // to the user. @@ -921,7 +921,7 @@ void Binding::OnResolveComplete(void * appState, INET_ERROR err, uint8_t addrCou */ void Binding::OnConnectionComplete(ChipConnection * con, CHIP_ERROR conErr) { - Binding * _this = (Binding *) con->AppState; + Binding * _this = static_cast(con->AppState); VerifyOrDie(_this->mState == kState_PreparingTransport_TCPConnect); VerifyOrDie(_this->mCon == con); @@ -995,7 +995,7 @@ void Binding::OnConnectionClosed(ChipConnection * con, CHIP_ERROR err) void Binding::OnSecureSessionReady(ChipSecurityManager * sm, ChipConnection * con, void * reqState, uint16_t keyId, uint64_t peerNodeId, uint8_t encType) { - Binding * _this = (Binding *) reqState; + Binding * _this = static_cast(reqState); // Verify the state of the binding. VerifyOrDie(_this->mState == kState_PreparingSecurity_EstablishSession); @@ -1017,7 +1017,7 @@ void Binding::OnSecureSessionReady(ChipSecurityManager * sm, ChipConnection * co void Binding::OnSecureSessionFailed(ChipSecurityManager * sm, ChipConnection * con, void * reqState, CHIP_ERROR localErr, uint64_t peerNodeId, Protocols::StatusReporting::StatusReport * statusReport) { - Binding * _this = (Binding *) reqState; + Binding * _this = static_cast(reqState); // Verify the state of the binding. VerifyOrDie(_this->mState == kState_PreparingSecurity_EstablishSession); @@ -1445,7 +1445,7 @@ Binding::Configuration & Binding::Configuration::TargetAddress_IP(const char * a { mBinding.mAddressingOption = Binding::kAddressing_HostName; mBinding.mHostName = aHostName; - mBinding.mHostNameLen = (uint8_t) aHostNameLen; + mBinding.mHostNameLen = static_cast(aHostNameLen); mBinding.mPeerPort = (aPeerPort != 0) ? aPeerPort : CHIP_PORT; mBinding.mInterfaceId = aInterfaceId; } diff --git a/src/lib/message/CHIPConnection.cpp b/src/lib/message/CHIPConnection.cpp index 20b8f2e2acb22c..a235392db8b94b 100644 --- a/src/lib/message/CHIPConnection.cpp +++ b/src/lib/message/CHIPConnection.cpp @@ -1018,7 +1018,7 @@ void ChipConnection::DoClose(CHIP_ERROR err, uint8_t flags) void ChipConnection::HandleResolveComplete(void * appState, INET_ERROR dnsRes, uint8_t addrCount, IPAddress * addrArray) { - ChipConnection * con = (ChipConnection *) appState; + ChipConnection * con = static_cast(appState); // It is legal for a DNS entry to exist but contain no A/AAAA records. If this happens, return a reasonable error // to the user. @@ -1147,7 +1147,7 @@ CHIP_ERROR ChipConnection::StartConnect() void ChipConnection::HandleConnectComplete(TCPEndPoint * endPoint, INET_ERROR conRes) { - ChipConnection * con = (ChipConnection *) endPoint->AppState; + ChipConnection * con = static_cast(endPoint->AppState); ChipLogProgress(MessageLayer, "TCP con complete %04X %ld", con->LogId(), (long) conRes); @@ -1220,7 +1220,7 @@ void ChipConnection::HandleConnectComplete(TCPEndPoint * endPoint, INET_ERROR co void ChipConnection::HandleDataReceived(TCPEndPoint * endPoint, PacketBuffer * data) { CHIP_ERROR err; - ChipConnection * con = (ChipConnection *) endPoint->AppState; + ChipConnection * con = static_cast(endPoint->AppState); ChipMessageLayer * msgLayer = con->MessageLayer; // While in a state that allows receiving, process the received data... @@ -1404,7 +1404,7 @@ void ChipConnection::HandleDataReceived(TCPEndPoint * endPoint, PacketBuffer * d void ChipConnection::HandleTcpConnectionClosed(TCPEndPoint * endPoint, INET_ERROR err) { - ChipConnection * con = (ChipConnection *) endPoint->AppState; + ChipConnection * con = static_cast(endPoint->AppState); if (err == INET_NO_ERROR && con->State == kState_EstablishingSession) err = CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY; con->DoClose(err, 0); @@ -1632,7 +1632,7 @@ void ChipConnection::HandleBleConnectComplete(BLEEndPoint * endPoint, BLE_ERROR void ChipConnection::HandleBleMessageReceived(BLEEndPoint * endPoint, PacketBuffer * data) { - ChipConnection * con = (ChipConnection *) endPoint->mAppState; + ChipConnection * con = static_cast(endPoint->mAppState); ChipMessageLayer * msgLayer = con->MessageLayer; // CHIP's BLE layer reassembles received messages in their entirety before it passes them up the stack, @@ -1691,7 +1691,7 @@ void ChipConnection::HandleBleMessageReceived(BLEEndPoint * endPoint, PacketBuff void ChipConnection::HandleBleConnectionClosed(BLEEndPoint * endPoint, BLE_ERROR err) { - ChipConnection * con = (ChipConnection *) endPoint->mAppState; + ChipConnection * con = static_cast(endPoint->mAppState); con->DoClose(err, 0); } diff --git a/src/lib/message/CHIPExchangeMgr.cpp b/src/lib/message/CHIPExchangeMgr.cpp index ea95a699a314f1..cf0954c268098e 100644 --- a/src/lib/message/CHIPExchangeMgr.cpp +++ b/src/lib/message/CHIPExchangeMgr.cpp @@ -315,7 +315,7 @@ ExchangeContext * ChipExchangeManager::FindContext(uint64_t peerNodeId, ChipConn CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profileId, ExchangeContext::MessageReceiveFunct handler, void * appState) { - return RegisterUMH(profileId, (int16_t) -1, nullptr, false, handler, appState); + return RegisterUMH(profileId, static_cast(-1), nullptr, false, handler, appState); } /** @@ -337,7 +337,7 @@ CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profi CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profileId, ExchangeContext::MessageReceiveFunct handler, bool allowDups, void * appState) { - return RegisterUMH(profileId, (int16_t) -1, nullptr, allowDups, handler, appState); + return RegisterUMH(profileId, static_cast(-1), nullptr, allowDups, handler, appState); } /** @@ -358,7 +358,7 @@ CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profi CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profileId, uint8_t msgType, ExchangeContext::MessageReceiveFunct handler, void * appState) { - return RegisterUMH(profileId, (int16_t) msgType, nullptr, false, handler, appState); + return RegisterUMH(profileId, static_cast(msgType), nullptr, false, handler, appState); } /** @@ -383,7 +383,7 @@ CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profi ExchangeContext::MessageReceiveFunct handler, bool allowDups, void * appState) { - return RegisterUMH(profileId, (int16_t) msgType, nullptr, allowDups, handler, appState); + return RegisterUMH(profileId, static_cast(msgType), nullptr, allowDups, handler, appState); } /** @@ -408,7 +408,7 @@ CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profi CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profileId, uint8_t msgType, ChipConnection * con, ExchangeContext::MessageReceiveFunct handler, void * appState) { - return RegisterUMH(profileId, (int16_t) msgType, con, false, handler, appState); + return RegisterUMH(profileId, static_cast(msgType), con, false, handler, appState); } /** @@ -437,7 +437,7 @@ CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profi ExchangeContext::MessageReceiveFunct handler, bool allowDups, void * appState) { - return RegisterUMH(profileId, (int16_t) msgType, con, allowDups, handler, appState); + return RegisterUMH(profileId, static_cast(msgType), con, allowDups, handler, appState); } /** @@ -451,7 +451,7 @@ CHIP_ERROR ChipExchangeManager::RegisterUnsolicitedMessageHandler(uint32_t profi */ CHIP_ERROR ChipExchangeManager::UnregisterUnsolicitedMessageHandler(uint32_t profileId) { - return UnregisterUMH(profileId, (int16_t) -1, nullptr); + return UnregisterUMH(profileId, static_cast(-1), nullptr); } /** @@ -467,7 +467,7 @@ CHIP_ERROR ChipExchangeManager::UnregisterUnsolicitedMessageHandler(uint32_t pro */ CHIP_ERROR ChipExchangeManager::UnregisterUnsolicitedMessageHandler(uint32_t profileId, uint8_t msgType) { - return UnregisterUMH(profileId, (int16_t) msgType, nullptr); + return UnregisterUMH(profileId, static_cast(msgType), nullptr); } /** @@ -486,7 +486,7 @@ CHIP_ERROR ChipExchangeManager::UnregisterUnsolicitedMessageHandler(uint32_t pro */ CHIP_ERROR ChipExchangeManager::UnregisterUnsolicitedMessageHandler(uint32_t profileId, uint8_t msgType, ChipConnection * con) { - return UnregisterUMH(profileId, (int16_t) msgType, con); + return UnregisterUMH(profileId, static_cast(msgType), con); } void ChipExchangeManager::HandleAcceptError(ChipMessageLayer * msgLayer, CHIP_ERROR err) @@ -1731,7 +1731,7 @@ void ChipExchangeManager::RMPStartTimer() ChipLogProgress(ExchangeManager, "RMPStartTimer set timer for %d %" PRIu64, timerArmValue, timerExpiryEpoch); #endif RMPStopTimer(); - res = MessageLayer->SystemLayer->StartTimer((uint32_t) timerArmValue, RMPTimeout, this); + res = MessageLayer->SystemLayer->StartTimer(static_cast(timerArmValue), RMPTimeout, this); VerifyOrDieWithMsg(res == CHIP_NO_ERROR, ExchangeManager, "Cannot start RMPTimeout\n"); mRMPCurrentTimerExpiry = timerExpiryEpoch; diff --git a/src/lib/message/CHIPFabricState.cpp b/src/lib/message/CHIPFabricState.cpp index 09b1161c4e5452..00255338abdd59 100644 --- a/src/lib/message/CHIPFabricState.cpp +++ b/src/lib/message/CHIPFabricState.cpp @@ -138,7 +138,7 @@ void ChipSessionKey::Init() void ChipSessionKey::Clear() { Init(); - ClearSecretData((uint8_t *) &MsgEncKey.EncKey, sizeof(MsgEncKey.EncKey)); + ClearSecretData(reinterpret_cast(&MsgEncKey.EncKey), sizeof(MsgEncKey.EncKey)); } /** @@ -620,7 +620,7 @@ void ChipFabricState::RemoveSharedSessionEndNodes(const ChipSessionKey * session { if (endNode->SessionKey == sessionKey) { - memset((uint8_t *) endNode, 0, sizeof(SharedSessionEndNode)); + memset(reinterpret_cast(endNode), 0, sizeof(SharedSessionEndNode)); } } } @@ -732,7 +732,7 @@ CHIP_ERROR ChipFabricState::SuspendSession(uint16_t keyId, uint64_t peerNodeId, err = writer.Finalize(); SuccessOrExit(err); - serializedSessionLen = (uint16_t) writer.GetLengthWritten(); + serializedSessionLen = static_cast(writer.GetLengthWritten()); } // Mark the session key as suspended. @@ -740,7 +740,7 @@ CHIP_ERROR ChipFabricState::SuspendSession(uint16_t keyId, uint64_t peerNodeId, // Wipe the key. sessionKey->MsgEncKey.EncType = kChipEncryptionType_None; - ClearSecretData((uint8_t *) &sessionKey->MsgEncKey.EncKey, sizeof(sessionKey->MsgEncKey.EncKey)); + ClearSecretData(reinterpret_cast(&sessionKey->MsgEncKey.EncKey), sizeof(sessionKey->MsgEncKey.EncKey)); exit: // If something goes wrong, make sure we don't leave any key material behind. @@ -1079,7 +1079,7 @@ void ChipFabricState::OnMsgCounterSyncRespRcvd(uint64_t peerNodeId, uint32_t pee void ChipFabricState::StartMsgCounterSyncTimer() { // Arm timer to call MsgCounterSyncRespTimeout after CHIP_CONFIG_MSG_COUNTER_SYNC_RESP_TIMEOUT. - CHIP_ERROR res = MessageLayer->SystemLayer->StartTimer((uint32_t) CHIP_CONFIG_MSG_COUNTER_SYNC_RESP_TIMEOUT, + CHIP_ERROR res = MessageLayer->SystemLayer->StartTimer(static_cast(CHIP_CONFIG_MSG_COUNTER_SYNC_RESP_TIMEOUT), OnMsgCounterSyncRespTimeout, this); VerifyOrDie(res == CHIP_NO_ERROR); } @@ -1389,7 +1389,7 @@ CHIP_ERROR ChipFabricState::GetPassword(uint8_t pwSrc, const char *& ps, uint16_ if (PairingCode == nullptr) return CHIP_ERROR_INVALID_ARGUMENT; // TODO: use proper error code ps = PairingCode; - pwLen = (uint16_t) strlen(PairingCode); + pwLen = static_cast(strlen(PairingCode)); return CHIP_NO_ERROR; default: return CHIP_ERROR_INVALID_ARGUMENT; // TODO: use proper error code @@ -1425,7 +1425,7 @@ CHIP_ERROR ChipFabricState::CreateFabric() // uniqueness. do { - err = chip::Platform::Security::GetSecureRandomData((unsigned char *) &FabricId, sizeof(FabricId)); + err = chip::Platform::Security::GetSecureRandomData(reinterpret_cast(&FabricId), sizeof(FabricId)); SuccessOrExit(err); } while (FabricId == kFabricIdNotSpecified || FabricId >= kReservedFabricIdStart); } @@ -1453,7 +1453,7 @@ CHIP_ERROR ChipFabricState::CreateFabric() if (err != CHIP_NO_ERROR) ClearFabricState(); - ClearSecretData((uint8_t *) &fabricSecret, sizeof(fabricSecret)); + ClearSecretData(reinterpret_cast(&fabricSecret), sizeof(fabricSecret)); return err; } @@ -1510,10 +1510,10 @@ CHIP_ERROR ChipFabricState::GetFabricState(uint8_t * buf, uint32_t bufSize, uint err = writer.StartContainer(AnonymousTag, kTLVType_Structure, containerType3); SuccessOrExit(err); - err = writer.Put(ContextTag(kTag_FabricKeyId), (uint16_t)(fabricSecret.KeyId)); + err = writer.Put(ContextTag(kTag_FabricKeyId), static_cast(fabricSecret.KeyId)); SuccessOrExit(err); - err = writer.Put(ContextTag(kTag_EncryptionType), (uint8_t) kChipEncryptionType_AES128CTRSHA1); + err = writer.Put(ContextTag(kTag_EncryptionType), static_cast(kChipEncryptionType_AES128CTRSHA1)); SuccessOrExit(err); err = writer.PutBytes(ContextTag(kTag_DataKey), fabricSecret.Key, ChipEncryptionKey_AES128CTRSHA1::DataKeySize); @@ -1523,10 +1523,10 @@ CHIP_ERROR ChipFabricState::GetFabricState(uint8_t * buf, uint32_t bufSize, uint ChipEncryptionKey_AES128CTRSHA1::IntegrityKeySize); SuccessOrExit(err); - err = writer.Put(ContextTag(kTag_KeyScope), (FabricSecretScope) kFabricSecretScope_All); + err = writer.Put(ContextTag(kTag_KeyScope), static_cast(kFabricSecretScope_All)); SuccessOrExit(err); - err = writer.Put(ContextTag(kTag_RotationScheme), (FabricSecretRotationScheme) kDeprecatedRotationScheme); + err = writer.Put(ContextTag(kTag_RotationScheme), static_cast(kDeprecatedRotationScheme)); SuccessOrExit(err); err = writer.EndContainer(containerType3); @@ -1782,7 +1782,7 @@ bool ChipSessionState::IsDuplicateMessage(uint32_t msgId) // (send-rate * 2^31) past a message's original send time, while allowing (send-rate * (2^31 - 1)) time // between message arrivals before a new message will be mistakenly considered a duplicate. // - delta = (int32_t)(msgId - *MaxMsgIdRcvd); + delta = static_cast(msgId - *MaxMsgIdRcvd); // If the new message was sent after the max id message... if (delta > 0) @@ -2070,7 +2070,7 @@ void ChipMsgEncryptionKeyCache::Reset() // Clear key cache entry. void ChipMsgEncryptionKeyCache::Clear(uint8_t keyEntryIndex) { - ClearSecretData((uint8_t *) (&mKeyCache[keyEntryIndex]), sizeof(ChipMsgEncryptionKey)); + ClearSecretData(reinterpret_cast(&mKeyCache[keyEntryIndex]), sizeof(ChipMsgEncryptionKey)); mKeyCache[keyEntryIndex].KeyId = ChipKeyId::kNone; mKeyCache[keyEntryIndex].EncType = kChipEncryptionType_None; } diff --git a/src/lib/message/CHIPFabricState.h b/src/lib/message/CHIPFabricState.h index 323c006331868a..f46502858df007 100644 --- a/src/lib/message/CHIPFabricState.h +++ b/src/lib/message/CHIPFabricState.h @@ -234,7 +234,7 @@ inline bool IsGroupKeyAuthMode(ChipAuthMode authMode) */ inline uint8_t PasswordSourceFromAuthMode(ChipAuthMode authMode) { - return (uint8_t)(authMode & kChipAuthMode_PASE_PasswordSourceMask); + return static_cast(authMode & kChipAuthMode_PASE_PasswordSourceMask); } /** Returns the password source for the given authentication mode. @@ -243,7 +243,7 @@ inline uint8_t PasswordSourceFromAuthMode(ChipAuthMode authMode) */ inline uint8_t CertTypeFromAuthMode(ChipAuthMode authMode) { - return (uint8_t)(authMode & kChipAuthMode_CASE_CertTypeMask); + return static_cast(authMode & kChipAuthMode_CASE_CertTypeMask); } /** Returns the application group master key ID associated with the authentication mode. diff --git a/src/lib/message/CHIPMessageLayer.cpp b/src/lib/message/CHIPMessageLayer.cpp index 4dd1b07f9f02f5..b377dd1a23e57f 100644 --- a/src/lib/message/CHIPMessageLayer.cpp +++ b/src/lib/message/CHIPMessageLayer.cpp @@ -963,17 +963,21 @@ CHIP_ERROR ChipMessageLayer::SelectDestNodeIdAndAddress(uint64_t & destNodeId, I // Encode and return message header field value. static uint16_t EncodeHeaderField(const ChipMessageInfo * msgInfo) { - return ((((uint16_t) msgInfo->Flags) << kMsgHeaderField_FlagsShift) & kMsgHeaderField_FlagsMask) | - ((((uint16_t) msgInfo->EncryptionType) << kMsgHeaderField_EncryptionTypeShift) & kMsgHeaderField_EncryptionTypeMask) | - ((((uint16_t) msgInfo->MessageVersion) << kMsgHeaderField_MessageVersionShift) & kMsgHeaderField_MessageVersionMask); + return (((static_cast(msgInfo->Flags)) << kMsgHeaderField_FlagsShift) & kMsgHeaderField_FlagsMask) | + (((static_cast(msgInfo->EncryptionType)) << kMsgHeaderField_EncryptionTypeShift) & + kMsgHeaderField_EncryptionTypeMask) | + (((static_cast(msgInfo->MessageVersion)) << kMsgHeaderField_MessageVersionShift) & + kMsgHeaderField_MessageVersionMask); } // Decode message header field value. static void DecodeHeaderField(const uint16_t headerField, ChipMessageInfo * msgInfo) { - msgInfo->Flags = (uint16_t)((headerField & kMsgHeaderField_FlagsMask) >> kMsgHeaderField_FlagsShift); - msgInfo->EncryptionType = (uint8_t)((headerField & kMsgHeaderField_EncryptionTypeMask) >> kMsgHeaderField_EncryptionTypeShift); - msgInfo->MessageVersion = (uint8_t)((headerField & kMsgHeaderField_MessageVersionMask) >> kMsgHeaderField_MessageVersionShift); + msgInfo->Flags = static_cast((headerField & kMsgHeaderField_FlagsMask) >> kMsgHeaderField_FlagsShift); + msgInfo->EncryptionType = + static_cast((headerField & kMsgHeaderField_EncryptionTypeMask) >> kMsgHeaderField_EncryptionTypeShift); + msgInfo->MessageVersion = + static_cast((headerField & kMsgHeaderField_MessageVersionMask) >> kMsgHeaderField_MessageVersionShift); } /** @@ -1472,7 +1476,7 @@ CHIP_ERROR ChipMessageLayer::DecodeMessageWithLength(PacketBuffer * msgBuf, uint void ChipMessageLayer::HandleUDPMessage(UDPEndPoint * endPoint, PacketBuffer * msg, const IPPacketInfo * pktInfo) { CHIP_ERROR err = CHIP_NO_ERROR; - ChipMessageLayer * msgLayer = (ChipMessageLayer *) endPoint->AppState; + ChipMessageLayer * msgLayer = static_cast(endPoint->AppState); ChipMessageInfo msgInfo; uint64_t sourceNodeId; uint8_t * payload; @@ -1567,7 +1571,7 @@ void ChipMessageLayer::HandleUDPReceiveError(UDPEndPoint * endPoint, INET_ERROR { ChipLogError(MessageLayer, "HandleUDPReceiveError Error %s", ErrorStr(err)); - ChipMessageLayer * msgLayer = (ChipMessageLayer *) endPoint->AppState; + ChipMessageLayer * msgLayer = static_cast(endPoint->AppState); if (msgLayer->OnReceiveError != nullptr) msgLayer->OnReceiveError(msgLayer, err, pktInfo); } @@ -1575,7 +1579,7 @@ void ChipMessageLayer::HandleUDPReceiveError(UDPEndPoint * endPoint, INET_ERROR #if CONFIG_NETWORK_LAYER_BLE void ChipMessageLayer::HandleIncomingBleConnection(BLEEndPoint * bleEP) { - ChipMessageLayer * msgLayer = (ChipMessageLayer *) bleEP->mAppState; + ChipMessageLayer * msgLayer = static_cast(bleEP->mAppState); // Immediately close the connection if there's no callback registered. if (msgLayer->OnConnectionReceived == nullptr && msgLayer->ExchangeMgr == nullptr) @@ -1629,7 +1633,7 @@ void ChipMessageLayer::HandleIncomingTcpConnection(TCPEndPoint * listeningEP, TC uint16_t localPort; uint16_t incomingTCPConCount; uint16_t incomingTCPConCountFromIP; - ChipMessageLayer * msgLayer = (ChipMessageLayer *) listeningEP->AppState; + ChipMessageLayer * msgLayer = static_cast(listeningEP->AppState); // Immediately close the connection if there's no callback registered. if (msgLayer->OnConnectionReceived == nullptr && msgLayer->ExchangeMgr == nullptr) @@ -1704,7 +1708,7 @@ void ChipMessageLayer::HandleIncomingTcpConnection(TCPEndPoint * listeningEP, TC void ChipMessageLayer::HandleAcceptError(TCPEndPoint * ep, INET_ERROR err) { - ChipMessageLayer * msgLayer = (ChipMessageLayer *) ep->AppState; + ChipMessageLayer * msgLayer = static_cast(ep->AppState); if (msgLayer->OnAcceptError != nullptr) msgLayer->OnAcceptError(msgLayer, err); } diff --git a/src/lib/message/CHIPMessageLayer.h b/src/lib/message/CHIPMessageLayer.h index 7948e81e39051a..c3ba39a1616eff 100644 --- a/src/lib/message/CHIPMessageLayer.h +++ b/src/lib/message/CHIPMessageLayer.h @@ -976,7 +976,7 @@ typedef enum ChipSubnetId inline void ChipNodeAddrToStr(char * buf, uint32_t bufSize, uint64_t nodeId, const Inet::IPAddress * addr, uint16_t port, ChipConnection * con) { - ChipMessageLayer::GetPeerDescription(buf, (size_t) bufSize, nodeId, addr, port, INET_NULL_INTERFACEID, con); + ChipMessageLayer::GetPeerDescription(buf, static_cast(bufSize), nodeId, addr, port, INET_NULL_INTERFACEID, con); } /** @@ -984,7 +984,7 @@ inline void ChipNodeAddrToStr(char * buf, uint32_t bufSize, uint64_t nodeId, con */ inline void ChipMessageSourceToStr(char * buf, uint32_t bufSize, const ChipMessageInfo * msgInfo) { - ChipMessageLayer::GetPeerDescription(buf, (size_t) bufSize, msgInfo); + ChipMessageLayer::GetPeerDescription(buf, static_cast(bufSize), msgInfo); } extern CHIP_ERROR GenerateChipNodeId(uint64_t & nodeId); diff --git a/src/lib/message/CHIPSecurityMgr.cpp b/src/lib/message/CHIPSecurityMgr.cpp index e657eaf01f5633..c6c8ce7e4b7be9 100644 --- a/src/lib/message/CHIPSecurityMgr.cpp +++ b/src/lib/message/CHIPSecurityMgr.cpp @@ -133,7 +133,7 @@ void ChipSecurityManager::HandleUnsolicitedMessage(ExchangeContext * ec, const I PacketBuffer * msgBuf) { CHIP_ERROR err = CHIP_NO_ERROR; - ChipSecurityManager * secMgr = (ChipSecurityManager *) ec->AppState; + ChipSecurityManager * secMgr = static_cast(ec->AppState); // Handle Key Error Messages. if (profileId == kChipProtocol_Security && msgType == kMsgType_KeyError) @@ -709,7 +709,7 @@ void ChipSecurityManager::HandleSessionError(CHIP_ERROR err, PacketBuffer * stat void ChipSecurityManager::HandleConnectionClosed(ExchangeContext * ec, ChipConnection * con, CHIP_ERROR conErr) { - ChipSecurityManager * secMgr = (ChipSecurityManager *) ec->AppState; + ChipSecurityManager * secMgr = static_cast(ec->AppState); if (conErr == CHIP_NO_ERROR) conErr = CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY; @@ -903,7 +903,7 @@ void ChipSecurityManager::StopIdleSessionTimer() void ChipSecurityManager::HandleIdleSessionTimeout(System::Layer * aLayer, void * aAppState, System::Error aError) { - ChipSecurityManager * _this = (ChipSecurityManager *) aAppState; + ChipSecurityManager * _this = static_cast(aAppState); bool unreservedSessionsExist; ClearFlag(_this->mFlags, kFlag_IdleSessionTimerRunning); @@ -929,7 +929,7 @@ void ChipSecurityManager::RMPHandleAckRcvd(ExchangeContext * ec, void * msgCtxt) void ChipSecurityManager::RMPHandleSendError(ExchangeContext * ec, CHIP_ERROR err, void * msgCtxt) { ChipLogProgress(SecurityManager, "%s", __FUNCTION__); - ChipSecurityManager * secMgr = (ChipSecurityManager *) ec->AppState; + ChipSecurityManager * secMgr = static_cast(ec->AppState); secMgr->HandleSessionError(err, nullptr); } @@ -941,7 +941,7 @@ void ChipSecurityManager::AsyncNotifySecurityManagerAvailable() void ChipSecurityManager::DoNotifySecurityManagerAvailable(System::Layer * systemLayer, void * appState, System::Error err) { - ChipSecurityManager * _this = (ChipSecurityManager *) appState; + ChipSecurityManager * _this = static_cast(appState); if (_this->State == kState_Idle) { _this->ExchangeManager->NotifySecurityManagerAvailable(); diff --git a/src/lib/message/CHIPServerBase.cpp b/src/lib/message/CHIPServerBase.cpp index 6846e6f8d157b3..1b0dd0f4ea7de7 100644 --- a/src/lib/message/CHIPServerBase.cpp +++ b/src/lib/message/CHIPServerBase.cpp @@ -174,7 +174,7 @@ CHIP_ERROR ChipServerBase::SendStatusReport(ExchangeContext * ec, uint32_t statu err = statusWriter.StartContainer(AnonymousTag, kTLVType_Structure, outerContainerType); SuccessOrExit(err); - err = statusWriter.Put(ProfileTag(kChipProtocol_Common, Common::kTag_SystemErrorCode), (uint32_t) sysError); + err = statusWriter.Put(ProfileTag(kChipProtocol_Common, Common::kTag_SystemErrorCode), static_cast(sysError)); SuccessOrExit(err); err = statusWriter.EndContainer(outerContainerType); diff --git a/src/lib/shell/shell.cpp b/src/lib/shell/shell.cpp index ca3cb5d3b169c0..ae12ea8bc1e1e6 100644 --- a/src/lib/shell/shell.cpp +++ b/src/lib/shell/shell.cpp @@ -49,7 +49,7 @@ int shell_line_read(char * buffer, size_t max) char * inptr = buffer; // Read in characters until we get a new line or we hit our max size. - while (((inptr - buffer) < (int) max) && !done) + while (((inptr - buffer) < static_cast(max)) && !done) { if (read == 0) { @@ -80,7 +80,7 @@ int shell_line_read(char * buffer, size_t max) } break; default: - if (isprint((int) *inptr) || *inptr == '\t') + if (isprint(static_cast(*inptr)) || *inptr == '\t') { streamer_printf(streamer_get(), "%c", *inptr); } diff --git a/src/lib/support/Base64.cpp b/src/lib/support/Base64.cpp index a043042b485bf2..060876fb15f57c 100644 --- a/src/lib/support/Base64.cpp +++ b/src/lib/support/Base64.cpp @@ -174,7 +174,7 @@ uint32_t Base64Encode32(const uint8_t * in, uint32_t inLen, char * out, Base64Va while (true) { - uint16_t inChunkLen = (inLen > kMaxConvert) ? (uint16_t) kMaxConvert : (uint16_t) inLen; + uint16_t inChunkLen = (inLen > kMaxConvert) ? static_cast(kMaxConvert) : static_cast(inLen); uint16_t outChunkLen = Base64Encode(in, inChunkLen, out, valToCharFunct); @@ -267,7 +267,7 @@ uint32_t Base64Decode32(const char * in, uint32_t inLen, uint8_t * out, Base64Ch while (true) { - uint16_t inChunkLen = (inLen > kMaxConvert) ? (uint16_t) kMaxConvert : (uint16_t) inLen; + uint16_t inChunkLen = (inLen > kMaxConvert) ? static_cast(kMaxConvert) : static_cast(inLen); uint16_t outChunkLen = Base64Decode(in, inChunkLen, out, charToValFunct); if (outChunkLen == UINT16_MAX) diff --git a/src/lib/support/CHIPArgParser.cpp b/src/lib/support/CHIPArgParser.cpp index 65350e31af1c1b..66c0b67ef566e8 100644 --- a/src/lib/support/CHIPArgParser.cpp +++ b/src/lib/support/CHIPArgParser.cpp @@ -500,7 +500,7 @@ bool ParseArgsFromString(const char * progName, const char * argStr, OptionSet * return false; } - argc = SplitArgs(argStrCopy, argv, (char *) progName); + argc = SplitArgs(argStrCopy, argv, const_cast(progName)); if (argc < 0) { PrintArgError("%s: Memory allocation failure\n", progName); @@ -1177,7 +1177,7 @@ static char * MakeShortOptions(OptionSet ** optSets) // The buffer needs to be big enough to hold up to 3 characters per short option plus an initial // ":" and a terminating null. size_t arraySize = 2 + (totalOptions * 3); - char * shortOpts = (char *) malloc(arraySize); + char * shortOpts = static_cast(malloc(arraySize)); if (shortOpts == nullptr) return nullptr; @@ -1196,7 +1196,7 @@ static char * MakeShortOptions(OptionSet ** optSets) // is optional. if (IsShortOptionChar(optDef->Id)) { - shortOpts[i++] = (char) optDef->Id; + shortOpts[i++] = static_cast(optDef->Id); if (optDef->ArgType != kNoArgument) shortOpts[i++] = ':'; if (optDef->ArgType == kArgumentOptional) @@ -1217,7 +1217,7 @@ static struct option * MakeLongOptions(OptionSet ** optSets) // Allocate an array to hold the list of long options. size_t arraySize = (sizeof(struct option) * (totalOptions + 1)); - struct option * longOpts = (struct option *) malloc(arraySize); + struct option * longOpts = static_cast(malloc(arraySize)); if (longOpts == nullptr) return nullptr; @@ -1229,7 +1229,7 @@ static struct option * MakeLongOptions(OptionSet ** optSets) for (OptionDef * optDef = (*optSets)->OptionDefs; optDef->Name != nullptr; optDef++) { longOpts[i].name = optDef->Name; - longOpts[i].has_arg = (int) optDef->ArgType; + longOpts[i].has_arg = static_cast(optDef->ArgType); longOpts[i].flag = nullptr; longOpts[i].val = optDef->Id; i++; @@ -1252,7 +1252,7 @@ static int32_t SplitArgs(char * argStr, char **& argList, char * initialArg) int32_t argCount = 0; // Allocate an array to hold pointers to the arguments. - argList = (char **) malloc(sizeof(char *) * InitialArgListSize); + argList = static_cast(malloc(sizeof(char *) * InitialArgListSize)); if (argList == nullptr) return -1; argListSize = InitialArgListSize; @@ -1260,7 +1260,7 @@ static int32_t SplitArgs(char * argStr, char **& argList, char * initialArg) // If an initial argument was supplied, make it the first argument in the array. if (initialArg != nullptr) { - argList[0] = (char *) initialArg; + argList[0] = initialArg; argCount = 1; } @@ -1278,7 +1278,7 @@ static int32_t SplitArgs(char * argStr, char **& argList, char * initialArg) if (argListSize == argCount + 1) { argListSize *= 2; - argList = (char **) realloc(argList, argListSize); + argList = static_cast(realloc(argList, argListSize)); if (argList == nullptr) return -1; } @@ -1403,7 +1403,7 @@ static const char ** MakeUniqueHelpGroupNamesList(OptionSet * optSets[]) size_t numOptSets = CountOptionSets(optSets); size_t numGroups = 0; - const char ** groupNames = (const char **) malloc(sizeof(const char *) * (numOptSets + 1)); + const char ** groupNames = static_cast(malloc(sizeof(const char *) * (numOptSets + 1))); if (groupNames == nullptr) return nullptr; diff --git a/src/lib/support/ErrorStr.cpp b/src/lib/support/ErrorStr.cpp index 96a1cdb200a737..f6cee466679f17 100644 --- a/src/lib/support/ErrorStr.cpp +++ b/src/lib/support/ErrorStr.cpp @@ -166,8 +166,8 @@ DLL_EXPORT void FormatError(char * buf, uint16_t bufSize, const char * subsys, i descSep = ""; } - (void) snprintf(buf, bufSize, "%s%sError %" PRId32 " (0x%08" PRIX32 ")%s%s", subsys, subsysSep, err, (uint32_t) err, descSep, - desc); + (void) snprintf(buf, bufSize, "%s%sError %" PRId32 " (0x%08" PRIX32 ")%s%s", subsys, subsysSep, err, static_cast(err), + descSep, desc); #endif // CHIP_CONFIG_SHORT_ERROR_STR } diff --git a/src/lib/support/TimeUtils.cpp b/src/lib/support/TimeUtils.cpp index 3449ba79660ebc..c10c234f1e8e0f 100644 --- a/src/lib/support/TimeUtils.cpp +++ b/src/lib/support/TimeUtils.cpp @@ -481,11 +481,11 @@ void SecondsSinceEpochToCalendarTime(uint32_t secondsSinceEpoch, uint16_t & year DaysSinceEpochToCalendarDate(daysSinceEpoch, year, month, dayOfMonth); - hour = (uint8_t)(timeOfDay / kSecondsPerHour); + hour = static_cast(timeOfDay / kSecondsPerHour); timeOfDay -= (hour * kSecondsPerHour); - minute = (uint8_t)(timeOfDay / kSecondsPerMinute); + minute = static_cast(timeOfDay / kSecondsPerMinute); timeOfDay -= (minute * kSecondsPerMinute); - second = (uint8_t) timeOfDay; + second = static_cast(timeOfDay); } } // namespace chip diff --git a/src/lib/support/tests/TestCHIPArgParser.cpp b/src/lib/support/tests/TestCHIPArgParser.cpp index 838e0d436638ea..c55fbceb59121f 100644 --- a/src/lib/support/tests/TestCHIPArgParser.cpp +++ b/src/lib/support/tests/TestCHIPArgParser.cpp @@ -690,7 +690,7 @@ static void HandleArgError(const char * msg, ...) va_end(ap); va_start(ap, msg); - sCallbackRecords[sCallbackRecordCount].Error = (char *) malloc(msgLen + 1); + sCallbackRecords[sCallbackRecordCount].Error = static_cast(malloc(msgLen + 1)); status = vsnprintf(sCallbackRecords[sCallbackRecordCount].Error, msgLen + 1, msg, ap); (void) status; va_end(ap); diff --git a/src/lib/support/tests/TestCHIPMem.cpp b/src/lib/support/tests/TestCHIPMem.cpp index 3cb61604e741c6..ae6ff6e05f5d28 100644 --- a/src/lib/support/tests/TestCHIPMem.cpp +++ b/src/lib/support/tests/TestCHIPMem.cpp @@ -51,23 +51,23 @@ static void TestMemAlloc_Malloc(nlTestSuite * inSuite, void * inContext) char * p3 = nullptr; // Verify long-term allocation - p1 = (char *) MemoryAlloc(64, true); + p1 = static_cast(MemoryAlloc(64, true)); NL_TEST_ASSERT(inSuite, p1 != nullptr); - p2 = (char *) MemoryAlloc(256, true); + p2 = static_cast(MemoryAlloc(256, true)); NL_TEST_ASSERT(inSuite, p2 != nullptr); chip::Platform::MemoryFree(p1); chip::Platform::MemoryFree(p2); // Verify short-term allocation - p1 = (char *) MemoryAlloc(256); + p1 = static_cast(MemoryAlloc(256)); NL_TEST_ASSERT(inSuite, p1 != nullptr); - p2 = (char *) MemoryAlloc(256); + p2 = static_cast(MemoryAlloc(256)); NL_TEST_ASSERT(inSuite, p2 != nullptr); - p3 = (char *) MemoryAlloc(256); + p3 = static_cast(MemoryAlloc(256)); NL_TEST_ASSERT(inSuite, p3 != nullptr); chip::Platform::MemoryFree(p1); @@ -77,7 +77,7 @@ static void TestMemAlloc_Malloc(nlTestSuite * inSuite, void * inContext) static void TestMemAlloc_Calloc(nlTestSuite * inSuite, void * inContext) { - char * p = (char *) MemoryCalloc(128, true); + char * p = static_cast(MemoryCalloc(128, true)); NL_TEST_ASSERT(inSuite, p != nullptr); for (int i = 0; i < 128; i++) @@ -88,10 +88,10 @@ static void TestMemAlloc_Calloc(nlTestSuite * inSuite, void * inContext) static void TestMemAlloc_Realloc(nlTestSuite * inSuite, void * inContext) { - char * pa = (char *) MemoryAlloc(128, true); + char * pa = static_cast(MemoryAlloc(128, true)); NL_TEST_ASSERT(inSuite, pa != nullptr); - char * pb = (char *) MemoryRealloc(pa, 256); + char * pb = static_cast(MemoryRealloc(pa, 256)); NL_TEST_ASSERT(inSuite, pb != nullptr); chip::Platform::MemoryFree(pb); diff --git a/src/lib/support/tests/TestPersistedStorageImplementation.cpp b/src/lib/support/tests/TestPersistedStorageImplementation.cpp index 1e992f54db54a1..468be19afcff2d 100644 --- a/src/lib/support/tests/TestPersistedStorageImplementation.cpp +++ b/src/lib/support/tests/TestPersistedStorageImplementation.cpp @@ -154,7 +154,7 @@ CHIP_ERROR Read(const char * aKey, uint32_t & aValue) it = sPersistentStore.find(aKey); VerifyOrExit(it != sPersistentStore.end(), err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND); - size_t aValueLength = Base64Decode(it->second.c_str(), strlen(it->second.c_str()), (uint8_t *) &aValue); + size_t aValueLength = Base64Decode(it->second.c_str(), strlen(it->second.c_str()), reinterpret_cast(&aValue)); VerifyOrExit(aValueLength == sizeof(uint32_t), err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); } @@ -178,7 +178,7 @@ CHIP_ERROR Write(const char * aKey, uint32_t aValue) char encodedValue[BASE64_ENCODED_LEN(sizeof(uint32_t)) + 1]; memset(encodedValue, 0, sizeof(encodedValue)); - Base64Encode((uint8_t *) &aValue, sizeof(aValue), encodedValue); + Base64Encode(reinterpret_cast(&aValue), sizeof(aValue), encodedValue); sPersistentStore[aKey] = encodedValue; } diff --git a/src/lib/support/verhoeff/Verhoeff32.cpp b/src/lib/support/verhoeff/Verhoeff32.cpp index 68e7cb6b6ad3cf..a023164cde0c39 100644 --- a/src/lib/support/verhoeff/Verhoeff32.cpp +++ b/src/lib/support/verhoeff/Verhoeff32.cpp @@ -139,7 +139,7 @@ bool Verhoeff32::ValidateCheckChar(const char * str, size_t strLen) int Verhoeff32::CharToVal(char ch) { if (ch >= '0' && ch <= 'y') - return sCharToValTable[(int) ch - '0']; + return sCharToValTable[static_cast(ch) - '0']; return -1; } diff --git a/src/lib/support/verhoeff/Verhoeff36.cpp b/src/lib/support/verhoeff/Verhoeff36.cpp index bd2125cd94125d..0e133c5d110aae 100644 --- a/src/lib/support/verhoeff/Verhoeff36.cpp +++ b/src/lib/support/verhoeff/Verhoeff36.cpp @@ -145,7 +145,7 @@ bool Verhoeff36::ValidateCheckChar(const char * str, size_t strLen) int Verhoeff36::CharToVal(char ch) { if (ch >= '0' && ch <= 'z') - return sCharToValTable[(int) ch - '0']; + return sCharToValTable[static_cast(ch) - '0']; return -1; } diff --git a/src/lwip/standalone/sys_arch.c b/src/lwip/standalone/sys_arch.c index a356307d9e343d..fd37f8fb479527 100644 --- a/src/lwip/standalone/sys_arch.c +++ b/src/lwip/standalone/sys_arch.c @@ -535,7 +535,7 @@ u32_t sys_arch_sem_wait(struct sys_sem ** s, u32_t timeout) } sem->c--; pthread_mutex_unlock(&(sem->mutex)); - return (u32_t) time_needed; + return time_needed; } /*-----------------------------------------------------------------------------------*/ void sys_sem_signal(struct sys_sem ** s) diff --git a/src/platform/Linux/BLEManagerImpl.cpp b/src/platform/Linux/BLEManagerImpl.cpp index bc7f41bd0e2f2d..2662db83164a16 100644 --- a/src/platform/Linux/BLEManagerImpl.cpp +++ b/src/platform/Linux/BLEManagerImpl.cpp @@ -188,12 +188,12 @@ CHIP_ERROR BLEManagerImpl::ConfigureBle(uint32_t aNodeId, bool aIsCentral) CHIP_ERROR BLEManagerImpl::StartBLEAdvertising() { - return StartBluezAdv((BluezEndpoint *) mpAppState); + return StartBluezAdv(static_cast(mpAppState)); } CHIP_ERROR BLEManagerImpl::StopBLEAdvertising() { - return StopBluezAdv((BluezEndpoint *) mpAppState); + return StopBluezAdv(static_cast(mpAppState)); } void BLEManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) @@ -494,7 +494,7 @@ void BLEManagerImpl::DriveBLEState() // Register the CHIPoBLE application with the Bluez BLE layer if needed. if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && !GetFlag(mFlags, kFlag_AppRegistered)) { - err = BluezGattsAppRegister((BluezEndpoint *) mpAppState); + err = BluezGattsAppRegister(static_cast(mpAppState)); SetFlag(mFlags, kFlag_ControlOpInProgress); ExitNow(); } @@ -511,7 +511,7 @@ void BLEManagerImpl::DriveBLEState() // be called again, and execution will proceed to the code below. if (!GetFlag(mFlags, kFlag_AdvertisingConfigured)) { - err = BluezAdvertisementSetup((BluezEndpoint *) mpAppState); + err = BluezAdvertisementSetup(static_cast(mpAppState)); ExitNow(); } diff --git a/src/platform/Linux/CHIPBluezHelper.cpp b/src/platform/Linux/CHIPBluezHelper.cpp index 3f402aa42d7e78..5ca664c9881786 100644 --- a/src/platform/Linux/CHIPBluezHelper.cpp +++ b/src/platform/Linux/CHIPBluezHelper.cpp @@ -294,7 +294,7 @@ static gboolean BluezCharacteristicReadValue(BluezGattCharacteristic1 * aChar, G { GVariant * val; ChipLogProgress(DeviceLayer, "Received BluezCharacteristicReadValue"); - val = (GVariant *) bluez_gatt_characteristic1_get_value(aChar); + val = bluez_gatt_characteristic1_get_value(aChar); bluez_gatt_characteristic1_complete_read_value(aChar, aInvocation, val); return TRUE; } @@ -359,7 +359,7 @@ static gboolean BluezCharacteristicWriteFD(GIOChannel * aChannel, GIOCondition a ChipLogProgress(DeviceLayer, "c1 %s mtu, %d", __func__, conn->mMtu); - buf = (gchar *) (g_malloc(conn->mMtu)); + buf = static_cast(g_malloc(conn->mMtu)); fd = g_io_channel_unix_get_fd(aChannel); len = read(fd, buf, conn->mMtu); @@ -370,7 +370,7 @@ static gboolean BluezCharacteristicWriteFD(GIOChannel * aChannel, GIOCondition a newVal = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, buf, static_cast(len), sizeof(uint8_t)); bluez_gatt_characteristic1_set_value(conn->mpC1, newVal); - BLEManagerImpl::HandleRXCharWrite(conn, (uint8_t *) (buf), static_cast(len)); + BLEManagerImpl::HandleRXCharWrite(conn, reinterpret_cast(buf), static_cast(len)); isSuccess = true; exit: @@ -439,8 +439,8 @@ static gboolean BluezCharacteristicAcquireWrite(BluezGattCharacteristic1 * aChar g_io_channel_set_buffered(channel, FALSE); conn->mC1Channel.mpChannel = channel; - conn->mC1Channel.mWatch = - g_io_add_watch(channel, (GIOCondition)(G_IO_HUP | G_IO_IN | G_IO_ERR | G_IO_NVAL), BluezCharacteristicWriteFD, conn); + conn->mC1Channel.mWatch = g_io_add_watch(channel, static_cast(G_IO_HUP | G_IO_IN | G_IO_ERR | G_IO_NVAL), + BluezCharacteristicWriteFD, conn); bluez_gatt_characteristic1_set_write_acquired(aChar, TRUE); @@ -501,8 +501,9 @@ static gboolean BluezCharacteristicAcquireNotify(BluezGattCharacteristic1 * aCha g_io_channel_set_close_on_unref(channel, TRUE); g_io_channel_set_buffered(channel, FALSE); conn->mC2Channel.mpChannel = channel; - conn->mC2Channel.mWatch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT_IDLE, (GIOCondition)(G_IO_HUP | G_IO_ERR | G_IO_NVAL), - bluezCharacteristicDestroyFD, conn, nullptr); + conn->mC2Channel.mWatch = + g_io_add_watch_full(channel, G_PRIORITY_DEFAULT_IDLE, static_cast(G_IO_HUP | G_IO_ERR | G_IO_NVAL), + bluezCharacteristicDestroyFD, conn, nullptr); bluez_gatt_characteristic1_set_notify_acquired(aChar, TRUE); @@ -597,7 +598,7 @@ static gboolean BluezCharacteristicStopNotify(BluezGattCharacteristic1 * aChar, static gboolean BluezCharacteristicConfirm(BluezGattCharacteristic1 * aChar, GDBusMethodInvocation * aInvocation, gpointer apClosure) { - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); BluezConnection * conn = GetBluezConnectionViaDevice(endpoint); ChipLogDetail(Ble, "Indication confirmation, %p", conn); @@ -718,7 +719,7 @@ static void BluezConnectionInit(BluezConnection * apConn) static gboolean BluezConnectionInitIdle(gpointer user_data) { - BluezConnection * conn = (BluezConnection *) user_data; + BluezConnection * conn = static_cast(user_data); ChipLogProgress(DeviceLayer, "%s", __func__); @@ -804,7 +805,7 @@ gboolean BluezPeripheralRegisterApp(void * apClosure) GVariantBuilder optionsBuilder; GVariant * options; - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); VerifyOrExit(endpoint->mpAdapter != nullptr, ChipLogProgress(DeviceLayer, "FAIL: NULL endpoint->mpAdapter in %s", __func__)); adapter = g_dbus_interface_get_object(G_DBUS_INTERFACE(endpoint->mpAdapter)); @@ -881,7 +882,7 @@ static void BluezSignalInterfacePropertiesChanged(GDBusObjectManagerClient * aMa const gchar * const * aInvalidatedProps, gpointer apClosure) { - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); VerifyOrExit(endpoint != nullptr, ChipLogProgress(DeviceLayer, "endpoint is NULL in %s", __func__)); VerifyOrExit(endpoint->mpAdapter != nullptr, ChipLogProgress(DeviceLayer, "FAIL: NULL endpoint->mpAdapter in %s", __func__)); @@ -895,7 +896,7 @@ static void BluezSignalInterfacePropertiesChanged(GDBusObjectManagerClient * aMa if (BluezIsDeviceOnAdapter(device, endpoint->mpAdapter)) { BluezConnection * conn = - (BluezConnection *) g_hash_table_lookup(endpoint->mpConnMap, g_dbus_proxy_get_object_path(aInterface)); + static_cast(g_hash_table_lookup(endpoint->mpConnMap, g_dbus_proxy_get_object_path(aInterface))); g_variant_iter_init(&iter, aChangedProperties); while (g_variant_iter_next(&iter, "{&sv}", &key, &value)) { @@ -919,7 +920,7 @@ static void BluezSignalInterfacePropertiesChanged(GDBusObjectManagerClient * aMa g_dbus_proxy_get_object_path(aInterface))); conn = g_new0(BluezConnection, 1); conn->mpPeerAddress = g_strdup(bluez_device1_get_address(device)); - conn->mpDevice = (BluezDevice1 *) g_object_ref(device); + conn->mpDevice = static_cast(g_object_ref(device)); conn->mpEndpoint = endpoint; BluezConnectionInit(conn); endpoint->mpPeerDevicePath = g_strdup(g_dbus_proxy_get_object_path(aInterface)); @@ -988,14 +989,15 @@ static void BluezHandleNewDevice(BluezDevice1 * device, BluezEndpoint * apEndpoi BluezConnection * conn; SuccessOrExit(bluez_device1_get_connected(device)); - conn = (BluezConnection *) g_hash_table_lookup(apEndpoint->mpConnMap, g_dbus_proxy_get_object_path(G_DBUS_PROXY(device))); + conn = static_cast( + g_hash_table_lookup(apEndpoint->mpConnMap, g_dbus_proxy_get_object_path(G_DBUS_PROXY(device)))); VerifyOrExit(conn == nullptr, ChipLogProgress(DeviceLayer, "FAIL: connection already tracked: conn: %x new device: %s", conn, g_dbus_proxy_get_object_path(G_DBUS_PROXY(device)))); conn = g_new0(BluezConnection, 1); conn->mpPeerAddress = g_strdup(bluez_device1_get_address(device)); - conn->mpDevice = (BluezDevice1 *) g_object_ref(device); + conn->mpDevice = static_cast(g_object_ref(device)); conn->mpEndpoint = apEndpoint; BluezConnectionInit(conn); @@ -1013,7 +1015,7 @@ static void BluezSignalOnObjectAdded(GDBusObjectManager * aManager, GDBusObject BluezObject * o = BLUEZ_OBJECT(aObject); BluezDevice1 * device = bluez_object_get_device1(o); - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); if (device != nullptr) { if (BluezIsDeviceOnAdapter(device, endpoint->mpAdapter) == TRUE) @@ -1036,7 +1038,7 @@ static BluezGattService1 * BluezServiceCreate(gpointer apClosure) { BluezObjectSkeleton * object; BluezGattService1 * service; - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); endpoint->mpServicePath = g_strdup_printf("%s/service", endpoint->mpRootPath); ChipLogProgress(DeviceLayer, "CREATE service object at %s", endpoint->mpServicePath); @@ -1078,19 +1080,19 @@ static void bluezObjectsSetup(BluezEndpoint * apEndpoint) if (BLUEZ_IS_ADAPTER1(ll->data)) { // we found the adapter BluezAdapter1 * adapter = BLUEZ_ADAPTER1(ll->data); - char * addr = (char *) bluez_adapter1_get_address(adapter); + char * addr = const_cast(bluez_adapter1_get_address(adapter)); if (apEndpoint->mpAdapterAddr == nullptr) // no adapter address provided, bind to the hci indicated by nodeid { if (strcmp(g_dbus_proxy_get_object_path(G_DBUS_PROXY(adapter)), expectedPath) == 0) { - apEndpoint->mpAdapter = (BluezAdapter1 *) g_object_ref(adapter); + apEndpoint->mpAdapter = static_cast(g_object_ref(adapter)); } } else { if (strcmp(apEndpoint->mpAdapterAddr, addr) == 0) { - apEndpoint->mpAdapter = (BluezAdapter1 *) g_object_ref(adapter); + apEndpoint->mpAdapter = static_cast(g_object_ref(adapter)); } } } @@ -1113,7 +1115,8 @@ static void bluezObjectsSetup(BluezEndpoint * apEndpoint) static BluezConnection * GetBluezConnectionViaDevice(BluezEndpoint * apEndpoint) { - BluezConnection * retval = (BluezConnection *) g_hash_table_lookup(apEndpoint->mpConnMap, apEndpoint->mpPeerDevicePath); + BluezConnection * retval = + static_cast(g_hash_table_lookup(apEndpoint->mpConnMap, apEndpoint->mpPeerDevicePath)); // ChipLogProgress(DeviceLayer, "acquire connection object %p in (%s)", retval, __func__); return retval; } @@ -1263,7 +1266,7 @@ static void BluezPeripheralObjectsSetup(gpointer apClosure) static const char * const c1_flags[] = { "write", nullptr }; static const char * const c2_flags[] = { "read", "indicate", nullptr }; - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); VerifyOrExit(endpoint != nullptr, ChipLogProgress(DeviceLayer, "endpoint is NULL in %s", __func__)); endpoint->mpService = BluezServiceCreate(apClosure); @@ -1300,7 +1303,7 @@ static void BluezPeripheralObjectsSetup(gpointer apClosure) static void BluezOnBusAcquired(GDBusConnection * aConn, const gchar * aName, gpointer apClosure) { - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); VerifyOrExit(endpoint != nullptr, ChipLogProgress(DeviceLayer, "endpoint is NULL in %s", __func__)); ChipLogProgress(DeviceLayer, "TRACE: Bus acquired for name %s", aName); @@ -1331,7 +1334,7 @@ static void * BluezMainLoop(void * apClosure) GDBusObjectManager * manager; GError * error = nullptr; GDBusConnection * conn = nullptr; - BluezEndpoint * endpoint = (BluezEndpoint *) apClosure; + BluezEndpoint * endpoint = static_cast(apClosure); VerifyOrExit(endpoint != nullptr, ChipLogProgress(DeviceLayer, "endpoint is NULL in %s", __func__)); conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error); diff --git a/src/platform/Linux/CHIPLinuxStorage.cpp b/src/platform/Linux/CHIPLinuxStorage.cpp index d2b4431f76eaa1..cacb1723d203db 100644 --- a/src/platform/Linux/CHIPLinuxStorage.cpp +++ b/src/platform/Linux/CHIPLinuxStorage.cpp @@ -152,11 +152,11 @@ CHIP_ERROR ChipLinuxStorage::WriteValue(const char * key, bool val) if (val) { - retval = WriteValue(key, (uint32_t) 1); + retval = WriteValue(key, static_cast(1)); } else { - retval = WriteValue(key, (uint32_t) 0); + retval = WriteValue(key, static_cast(0)); } return retval; diff --git a/src/setup_payload/QRCodeSetupPayloadGenerator.cpp b/src/setup_payload/QRCodeSetupPayloadGenerator.cpp index 3e5e3c0db027d9..ab4741a398372a 100644 --- a/src/setup_payload/QRCodeSetupPayloadGenerator.cpp +++ b/src/setup_payload/QRCodeSetupPayloadGenerator.cpp @@ -198,7 +198,7 @@ static CHIP_ERROR generateBitSet(SetupPayload & payload, uint8_t * bits, uint8_t err = populateBits(bits, offset, payload.vendorID, kVendorIDFieldLengthInBits, kTotalPayloadDataSizeInBits); err = populateBits(bits, offset, payload.productID, kProductIDFieldLengthInBits, kTotalPayloadDataSizeInBits); err = populateBits(bits, offset, payload.requiresCustomFlow, kCustomFlowRequiredFieldLengthInBits, kTotalPayloadDataSizeInBits); - err = populateBits(bits, offset, (uint16_t) payload.rendezvousInformation, kRendezvousInfoFieldLengthInBits, + err = populateBits(bits, offset, static_cast(payload.rendezvousInformation), kRendezvousInfoFieldLengthInBits, kTotalPayloadDataSizeInBits); err = populateBits(bits, offset, payload.discriminator, kPayloadDiscriminatorFieldLengthInBits, kTotalPayloadDataSizeInBits); err = populateBits(bits, offset, payload.setUpPINCode, kSetupPINCodeFieldLengthInBits, kTotalPayloadDataSizeInBits); diff --git a/src/setup_payload/QRCodeSetupPayloadParser.cpp b/src/setup_payload/QRCodeSetupPayloadParser.cpp index b81b4ba8027cb1..789e95771d5822 100644 --- a/src/setup_payload/QRCodeSetupPayloadParser.cpp +++ b/src/setup_payload/QRCodeSetupPayloadParser.cpp @@ -210,7 +210,7 @@ CHIP_ERROR QRCodeSetupPayloadParser::retrieveOptionalInfos(SetupPayload & outPay continue; } - tag = (uint8_t) TagNumFromTag(reader.GetTag()); + tag = static_cast(TagNumFromTag(reader.GetTag())); VerifyOrExit(IsContextTag(tag) == true || IsProfileTag(tag) == true, err = CHIP_ERROR_INVALID_TLV_TAG); optionalQRCodeInfoType elemType = optionalQRCodeInfoTypeUnknown; diff --git a/src/setup_payload/SetupPayloadHelper.cpp b/src/setup_payload/SetupPayloadHelper.cpp index f9c7ad3a0ba73a..234d28d965cbf9 100644 --- a/src/setup_payload/SetupPayloadHelper.cpp +++ b/src/setup_payload/SetupPayloadHelper.cpp @@ -109,15 +109,15 @@ static CHIP_ERROR addParameter(SetupPayload & setupPayload, const SetupPayloadPa { case SetupPayloadKey_Version: ChipLogDetail(SetupPayload, "Loaded version: %u", (uint8_t) parameter.uintValue); - setupPayload.version = (uint8_t) parameter.uintValue; + setupPayload.version = static_cast(parameter.uintValue); break; case SetupPayloadKey_VendorID: ChipLogDetail(SetupPayload, "Loaded vendorID: %u", (uint16_t) parameter.uintValue); - setupPayload.vendorID = (uint16_t) parameter.uintValue; + setupPayload.vendorID = static_cast(parameter.uintValue); break; case SetupPayloadKey_ProductID: ChipLogDetail(SetupPayload, "Loaded productID: %u", (uint16_t) parameter.uintValue); - setupPayload.productID = (uint16_t) parameter.uintValue; + setupPayload.productID = static_cast(parameter.uintValue); break; case SetupPayloadKey_RequiresCustomFlowTrue: ChipLogDetail(SetupPayload, "Requires custom flow was set to true"); @@ -129,11 +129,11 @@ static CHIP_ERROR addParameter(SetupPayload & setupPayload, const SetupPayloadPa break; case SetupPayloadKey_Discriminator: ChipLogDetail(SetupPayload, "Loaded discriminator: %u", (uint16_t) parameter.uintValue); - setupPayload.discriminator = (uint16_t) parameter.uintValue; + setupPayload.discriminator = static_cast(parameter.uintValue); break; case SetupPayloadKey_SetupPINCode: ChipLogDetail(SetupPayload, "Loaded setupPinCode: %lu", (unsigned long) parameter.uintValue); - setupPayload.setUpPINCode = (uint32_t) parameter.uintValue; + setupPayload.setUpPINCode = static_cast(parameter.uintValue); break; default: return CHIP_ERROR_INVALID_ARGUMENT; diff --git a/src/setup_payload/tests/TestQRCode.cpp b/src/setup_payload/tests/TestQRCode.cpp index 8cb1c2cde92769..e7f1534f146573 100644 --- a/src/setup_payload/tests/TestQRCode.cpp +++ b/src/setup_payload/tests/TestQRCode.cpp @@ -125,7 +125,7 @@ void TestBase41(nlTestSuite * inSuite, void * inContext) string hello_world; for (uint8_t b : decoded) { - hello_world += (char) b; + hello_world += static_cast(b); } NL_TEST_ASSERT(inSuite, hello_world == "Hello World!"); diff --git a/src/system/SystemPacketBuffer.cpp b/src/system/SystemPacketBuffer.cpp index 8ed191030dbae6..2eae7b76cf6b52 100644 --- a/src/system/SystemPacketBuffer.cpp +++ b/src/system/SystemPacketBuffer.cpp @@ -173,7 +173,7 @@ void PacketBuffer::SetDataLength(uint16_t aNewLen, PacketBuffer * aChainHead) ptrdiff_t lDelta = static_cast(aNewLen) - static_cast(this->len); this->len = aNewLen; - this->tot_len = (uint16_t)(this->tot_len + lDelta); + this->tot_len = static_cast(this->tot_len + lDelta); while (aChainHead != nullptr && aChainHead != this) { @@ -304,7 +304,7 @@ void PacketBuffer::CompactHead() memcpy(static_cast(this->payload) + this->len, lNextPacket.payload, lMoveLength); - lNextPacket.payload = (uint8_t *) lNextPacket.payload + lMoveLength; + lNextPacket.payload = static_cast(lNextPacket.payload) + lMoveLength; this->len = static_cast(this->len + lMoveLength); lAvailLength = static_cast(lAvailLength - lMoveLength); lNextPacket.len = static_cast(lNextPacket.len - lMoveLength); diff --git a/src/system/tests/TestSystemPacketBuffer.cpp b/src/system/tests/TestSystemPacketBuffer.cpp index 7dceec9d260f6c..a7c0ce2d5b3a14 100644 --- a/src/system/tests/TestSystemPacketBuffer.cpp +++ b/src/system/tests/TestSystemPacketBuffer.cpp @@ -189,7 +189,7 @@ PacketBuffer * PrepareTestBuffer(struct TestContext * theContext) */ void CheckStart(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -214,7 +214,7 @@ void CheckStart(nlTestSuite * inSuite, void * inContext) */ void CheckSetStart(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); static const ptrdiff_t sSizePacketBuffer = CHIP_SYSTEM_PACKETBUFFER_SIZE; for (size_t ith = 0; ith < kTestElements; ith++) @@ -275,7 +275,7 @@ void CheckSetStart(nlTestSuite * inSuite, void * inContext) */ void CheckDataLength(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -382,7 +382,7 @@ void CheckSetDataLength(nlTestSuite * inSuite, void * inContext) */ void CheckTotalLength(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -399,7 +399,7 @@ void CheckTotalLength(nlTestSuite * inSuite, void * inContext) */ void CheckMaxDataLength(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -416,7 +416,7 @@ void CheckMaxDataLength(nlTestSuite * inSuite, void * inContext) */ void CheckAvailableDataLength(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -434,7 +434,7 @@ void CheckAvailableDataLength(nlTestSuite * inSuite, void * inContext) */ void CheckReservedSize(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -665,7 +665,7 @@ void CheckCompactHead(nlTestSuite * inSuite, void * inContext) */ void CheckConsumeHead(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -799,7 +799,7 @@ void CheckConsume(nlTestSuite * inSuite, void * inContext) */ void CheckEnsureReservedSize(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -845,7 +845,7 @@ void CheckEnsureReservedSize(nlTestSuite * inSuite, void * inContext) */ void CheckAlignPayload(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -926,7 +926,7 @@ void CheckNext(nlTestSuite * inSuite, void * inContext) */ void CheckAddRef(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); for (size_t ith = 0; ith < kTestElements; ith++) { @@ -951,7 +951,7 @@ void CheckAddRef(nlTestSuite * inSuite, void * inContext) */ void CheckNewWithAvailableSizeAndFree(nlTestSuite * inSuite, void * inContext) { - struct TestContext * theContext = (struct TestContext *) (inContext); + struct TestContext * theContext = static_cast(inContext); PacketBuffer * buffer; for (size_t ith = 0; ith < kTestElements; ith++) diff --git a/src/transport/RendezvousSession.cpp b/src/transport/RendezvousSession.cpp index cb8237a7828c94..d34f3da44d26f9 100644 --- a/src/transport/RendezvousSession.cpp +++ b/src/transport/RendezvousSession.cpp @@ -190,7 +190,7 @@ void RendezvousSession::OnPairingError(CHIP_ERROR err) void RendezvousSession::OnPairingComplete() { - CHIP_ERROR err = mPairingSession.DeriveSecureSession((const unsigned char *) kSpake2pI2RSessionInfo, + CHIP_ERROR err = mPairingSession.DeriveSecureSession(reinterpret_cast(kSpake2pI2RSessionInfo), strlen(kSpake2pI2RSessionInfo), mSecureSession); VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Ble, "Failed to initialize a secure session: %s", ErrorStr(err))); @@ -389,15 +389,17 @@ CHIP_ERROR RendezvousSession::HandleSecureMessage(PacketBuffer * msgBuf) CHIP_ERROR RendezvousSession::WaitForPairing(Optional nodeId, uint32_t setupPINCode) { UpdateState(State::kSecurePairing); - return mPairingSession.WaitForPairing(setupPINCode, kSpake2p_Iteration_Count, (const unsigned char *) kSpake2pKeyExchangeSalt, + return mPairingSession.WaitForPairing(setupPINCode, kSpake2p_Iteration_Count, + reinterpret_cast(kSpake2pKeyExchangeSalt), strlen(kSpake2pKeyExchangeSalt), nodeId, 0, this); } CHIP_ERROR RendezvousSession::Pair(Optional nodeId, uint32_t setupPINCode) { UpdateState(State::kSecurePairing); - return mPairingSession.Pair(setupPINCode, kSpake2p_Iteration_Count, (const unsigned char *) kSpake2pKeyExchangeSalt, - strlen(kSpake2pKeyExchangeSalt), nodeId, mNextKeyId++, this); + return mPairingSession.Pair(setupPINCode, kSpake2p_Iteration_Count, + reinterpret_cast(kSpake2pKeyExchangeSalt), strlen(kSpake2pKeyExchangeSalt), + nodeId, mNextKeyId++, this); } void RendezvousSession::SendNetworkCredentials(const char * ssid, const char * passwd) diff --git a/src/transport/SecurePairingSession.cpp b/src/transport/SecurePairingSession.cpp index 6b373b93041f50..9670bed412b940 100644 --- a/src/transport/SecurePairingSession.cpp +++ b/src/transport/SecurePairingSession.cpp @@ -157,8 +157,8 @@ CHIP_ERROR SecurePairingSession::Pair(uint32_t peerSetUpPINCode, uint32_t pbkdf2 CHIP_ERROR err = Init(peerSetUpPINCode, pbkdf2IterCount, salt, saltLen, myNodeId, myKeyId, delegate); SuccessOrExit(err); - err = mSpake2p.BeginProver((const uint8_t *) "", 0, (const uint8_t *) "", 0, &mWS[0][0], kSpake2p_WS_Length, &mWS[1][0], - kSpake2p_WS_Length); + err = mSpake2p.BeginProver(reinterpret_cast(""), 0, reinterpret_cast(""), 0, &mWS[0][0], + kSpake2p_WS_Length, &mWS[1][0], kSpake2p_WS_Length); SuccessOrExit(err); err = mSpake2p.ComputeRoundOne(X, &X_len); @@ -231,8 +231,8 @@ CHIP_ERROR SecurePairingSession::HandleCompute_pA(const PacketHeader & header, S VerifyOrExit(buf != nullptr, err = CHIP_ERROR_MESSAGE_INCOMPLETE); VerifyOrExit(buf_len == kMAX_Point_Length, err = CHIP_ERROR_INVALID_MESSAGE_LENGTH); - err = mSpake2p.BeginVerifier((const uint8_t *) "", 0, (const uint8_t *) "", 0, &mWS[0][0], kSpake2p_WS_Length, mPoint, - sizeof(mPoint)); + err = mSpake2p.BeginVerifier(reinterpret_cast(""), 0, reinterpret_cast(""), 0, &mWS[0][0], + kSpake2p_WS_Length, mPoint, sizeof(mPoint)); SuccessOrExit(err); err = mSpake2p.ComputeRoundOne(Y, &Y_len); @@ -391,7 +391,7 @@ CHIP_ERROR SecurePairingSession::HandlePeerMessage(const PacketHeader & packetHe VerifyOrExit(payloadHeader.GetProtocolID() == Protocols::kChipProtocol_SecurePairing, err = CHIP_ERROR_INVALID_MESSAGE_TYPE); VerifyOrExit(payloadHeader.GetMessageType() == (uint8_t) mNextExpectedMsg, err = CHIP_ERROR_INVALID_MESSAGE_TYPE); - switch ((Spake2pMsgType) payloadHeader.GetMessageType()) + switch (static_cast(payloadHeader.GetMessageType())) { case Spake2pMsgType::kSpake2pCompute_pA: err = HandleCompute_pA(packetHeader, msg); diff --git a/src/transport/SecurePairingSession.h b/src/transport/SecurePairingSession.h index 755673ff188712..11416e1fdf00ec 100644 --- a/src/transport/SecurePairingSession.h +++ b/src/transport/SecurePairingSession.h @@ -242,8 +242,8 @@ class SecurePairingUsingTestSecret : public SecurePairingSession { const char * secret = "Test secret for key derivation"; size_t secretLen = strlen(secret); - return session.InitFromSecret((const uint8_t *) secret, secretLen, (const uint8_t *) "", 0, (const uint8_t *) secret, - secretLen); + return session.InitFromSecret(reinterpret_cast(secret), secretLen, reinterpret_cast(""), + 0, reinterpret_cast(secret), secretLen); } CHIP_ERROR HandlePeerMessage(const PacketHeader & packetHeader, System::PacketBuffer * msg) override { return CHIP_NO_ERROR; } diff --git a/src/transport/SecureSessionMgr.cpp b/src/transport/SecureSessionMgr.cpp index 7b725df3e16468..93ea29693ee244 100644 --- a/src/transport/SecureSessionMgr.cpp +++ b/src/transport/SecureSessionMgr.cpp @@ -201,8 +201,8 @@ CHIP_ERROR SecureSessionMgrBase::NewPairing(const OptionalDeriveSecureSession((const uint8_t *) kSpake2pI2RSessionInfo, strlen(kSpake2pI2RSessionInfo), - state->GetSecureSession()); + err = pairing->DeriveSecureSession(reinterpret_cast(kSpake2pI2RSessionInfo), + strlen(kSpake2pI2RSessionInfo), state->GetSecureSession()); } exit: diff --git a/src/transport/raw/MessageHeader.cpp b/src/transport/raw/MessageHeader.cpp index 109b79a86eae3d..d8841306e461e9 100644 --- a/src/transport/raw/MessageHeader.cpp +++ b/src/transport/raw/MessageHeader.cpp @@ -148,7 +148,7 @@ CHIP_ERROR PacketHeader::Decode(const uint8_t * const data, size_t size, uint16_ version = ((header & kVersionMask) >> kVersionShift); VerifyOrExit(version == kHeaderVersion, err = CHIP_ERROR_VERSION_MISMATCH); - mEncryptionType = (Header::EncryptionType)((header & kEncryptionTypeMask) >> kEncryptionTypeShift); + mEncryptionType = static_cast((header & kEncryptionTypeMask) >> kEncryptionTypeShift); mFlags.value = header & Header::Flags::kMask; mMessageId = LittleEndian::Read32(p); @@ -241,7 +241,7 @@ CHIP_ERROR PacketHeader::Encode(uint8_t * data, size_t size, uint16_t * encode_s header |= Header::Flags::kDestinationNodeIdPresent; } - header |= (static_cast((uint16_t) mEncryptionType << kEncryptionTypeShift) & kEncryptionTypeMask); + header |= (static_cast(static_cast(mEncryptionType) << kEncryptionTypeShift) & kEncryptionTypeMask); LittleEndian::Write16(p, header); LittleEndian::Write32(p, mMessageId); diff --git a/third_party/lwip/repo/lwip/src/core/dns.c b/third_party/lwip/repo/lwip/src/core/dns.c index 43f2fa89981303..be7deab23d0716 100644 --- a/third_party/lwip/repo/lwip/src/core/dns.c +++ b/third_party/lwip/repo/lwip/src/core/dns.c @@ -1489,8 +1489,9 @@ dns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, return; } /* skip this answer */ - if ((int)(res_idx + lwip_htons(ans.len)) > 0xFFFF) { - goto memerr; /* ignore this packet */ + if ((res_idx + lwip_htons(ans.len)) > 0xFFFF) + { + goto memerr; /* ignore this packet */ } res_idx += lwip_htons(ans.len); --nanswers; diff --git a/third_party/lwip/repo/lwip/src/core/ipv4/etharp.c b/third_party/lwip/repo/lwip/src/core/ipv4/etharp.c index 3f48a9975ff210..4a4cebac0da79e 100644 --- a/third_party/lwip/repo/lwip/src/core/ipv4/etharp.c +++ b/third_party/lwip/repo/lwip/src/core/ipv4/etharp.c @@ -802,8 +802,8 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) /* broadcast destination IP address? */ if (ip4_addr_isbroadcast(ipaddr, netif)) { /* broadcast on Ethernet also */ - dest = (const struct eth_addr *)ðbroadcast; - /* multicast destination IP address? */ + dest = ðbroadcast; + /* multicast destination IP address? */ } else if (ip4_addr_ismulticast(ipaddr)) { /* Hash IP multicast address to MAC address.*/ mcastaddr.addr[0] = LL_IP4_MULTICAST_ADDR_0; diff --git a/third_party/lwip/repo/lwip/src/core/ipv6/ip6_frag.c b/third_party/lwip/repo/lwip/src/core/ipv6/ip6_frag.c index ff07f71cd24afa..863a70e7a3369a 100644 --- a/third_party/lwip/repo/lwip/src/core/ipv6/ip6_frag.c +++ b/third_party/lwip/repo/lwip/src/core/ipv6/ip6_frag.c @@ -530,7 +530,7 @@ ip6_reass(struct pbuf *p) #if IPV6_FRAG_COPYHEADER if (IPV6_FRAG_REQROOM > 0) { /* hide the extra bytes borrowed from ip6_hdr for struct ip6_reass_helper */ - u8_t hdrerr = pbuf_header(next_pbuf, -(s16_t)(IPV6_FRAG_REQROOM)); + u8_t hdrerr = pbuf_header(next_pbuf, -(IPV6_FRAG_REQROOM)); LWIP_UNUSED_ARG(hdrerr); /* in case of LWIP_NOASSERT */ LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == 0); } @@ -547,7 +547,7 @@ ip6_reass(struct pbuf *p) #if IPV6_FRAG_COPYHEADER if (IPV6_FRAG_REQROOM > 0) { /* get back room for struct ip6_reass_helper (only required if sizeof(void*) > 4) */ - u8_t hdrerr = pbuf_header(ipr->p, -(s16_t)(IPV6_FRAG_REQROOM)); + u8_t hdrerr = pbuf_header(ipr->p, -(IPV6_FRAG_REQROOM)); LWIP_UNUSED_ARG(hdrerr); /* in case of LWIP_NOASSERT */ LWIP_ASSERT("no room for struct ip6_reass_helper", hdrerr == 0); } diff --git a/third_party/lwip/repo/lwip/src/core/mem.c b/third_party/lwip/repo/lwip/src/core/mem.c index d0771aa4b20562..dc06e0505facdb 100644 --- a/third_party/lwip/repo/lwip/src/core/mem.c +++ b/third_party/lwip/repo/lwip/src/core/mem.c @@ -430,14 +430,15 @@ mem_free(void *rmem) LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram && (u8_t *)rmem < (u8_t *)ram_end); - if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { - SYS_ARCH_DECL_PROTECT(lev); - LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_free: illegal memory\n")); - /* protect mem stats from concurrent access */ - SYS_ARCH_PROTECT(lev); - MEM_STATS_INC(illegal); - SYS_ARCH_UNPROTECT(lev); - return; + if ((u8_t *) rmem < ram || (u8_t *) rmem >= (u8_t *) ram_end) + { + SYS_ARCH_DECL_PROTECT(lev); + LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_free: illegal memory\n")); + /* protect mem stats from concurrent access */ + SYS_ARCH_PROTECT(lev); + MEM_STATS_INC(illegal); + SYS_ARCH_UNPROTECT(lev); + return; } /* protect the heap from concurrent access */ LWIP_MEM_FREE_PROTECT(); @@ -498,14 +499,15 @@ mem_trim(void *rmem, mem_size_t new_size) LWIP_ASSERT("mem_trim: legal memory", (u8_t *)rmem >= (u8_t *)ram && (u8_t *)rmem < (u8_t *)ram_end); - if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { - SYS_ARCH_DECL_PROTECT(lev); - LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_trim: illegal memory\n")); - /* protect mem stats from concurrent access */ - SYS_ARCH_PROTECT(lev); - MEM_STATS_INC(illegal); - SYS_ARCH_UNPROTECT(lev); - return rmem; + if ((u8_t *) rmem < ram || (u8_t *) rmem >= (u8_t *) ram_end) + { + SYS_ARCH_DECL_PROTECT(lev); + LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("mem_trim: illegal memory\n")); + /* protect mem stats from concurrent access */ + SYS_ARCH_PROTECT(lev); + MEM_STATS_INC(illegal); + SYS_ARCH_UNPROTECT(lev); + return rmem; } /* Get the corresponding struct mem ... */ /* cast through void* to get rid of alignment warnings */