From 2ab9b49042d90f0fe4d521d3888d94b592eb3b92 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 20 Mar 2019 09:27:41 -0700 Subject: [PATCH] [style] use C++-style casts (#3705) --- include/openthread/coap_secure.h | 4 ++-- src/cli/cli.cpp | 4 ++-- src/core/api/coap_secure_api.cpp | 7 +++---- src/core/api/thread_ftd_api.cpp | 2 +- src/core/meshcop/dtls.cpp | 18 ++++++++++-------- src/ncp/ncp_base.cpp | 2 +- src/ncp/spinel.c | 2 +- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/include/openthread/coap_secure.h b/include/openthread/coap_secure.h index 826dca3ca..e7d462366 100644 --- a/include/openthread/coap_secure.h +++ b/include/openthread/coap_secure.h @@ -128,8 +128,8 @@ otError otCoapSecureSetPsk(otInstance * aInstance, */ otError otCoapSecureGetPeerCertificateBase64(otInstance * aInstance, unsigned char *aPeerCert, - uint64_t * aCertLength, - uint64_t aCertBufferSize); + size_t * aCertLength, + size_t aCertBufferSize); /** * This method sets the authentication mode for the coap secure connection. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 84a0b5511..4faaf2775 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1799,7 +1799,7 @@ void Interpreter::ProcessNetworkName(int argc, char *argv[]) if (argc == 0) { otStringPtr networkName(otThreadGetNetworkName(mInstance)); - mServer->OutputFormat("%.*s\r\n", OT_NETWORK_NAME_MAX_SIZE, (const char *)networkName); + mServer->OutputFormat("%.*s\r\n", OT_NETWORK_NAME_MAX_SIZE, static_cast(networkName)); } else { @@ -3135,7 +3135,7 @@ void Interpreter::ProcessVersion(int argc, char *argv[]) OT_UNUSED_VARIABLE(argv); otStringPtr version(otGetVersionString()); - mServer->OutputFormat("%s\r\n", (const char *)version); + mServer->OutputFormat("%s\r\n", static_cast(version)); AppendResult(OT_ERROR_NONE); } diff --git a/src/core/api/coap_secure_api.cpp b/src/core/api/coap_secure_api.cpp index 59ec0aa6e..5f2c8acac 100644 --- a/src/core/api/coap_secure_api.cpp +++ b/src/core/api/coap_secure_api.cpp @@ -127,14 +127,13 @@ otError otCoapSecureSetPsk(otInstance * aInstance, otError otCoapSecureGetPeerCertificateBase64(otInstance * aInstance, unsigned char *aPeerCert, - uint64_t * aCertLength, - uint64_t aCertBufferSize) + size_t * aCertLength, + size_t aCertBufferSize) { #ifdef MBEDTLS_BASE64_C Instance &instance = *static_cast(aInstance); - return instance.GetApplicationCoapSecure().GetPeerCertificateBase64(aPeerCert, (size_t *)aCertLength, - (size_t)aCertBufferSize); + return instance.GetApplicationCoapSecure().GetPeerCertificateBase64(aPeerCert, aCertLength, aCertBufferSize); #else OT_UNUSED_VARIABLE(aInstance); OT_UNUSED_VARIABLE(aPeerCert); diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index ee21adc92..4e8c6c594 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -149,7 +149,7 @@ void otThreadSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout) { Instance &instance = *static_cast(aInstance); - instance.GetThreadNetif().GetMle().SetNetworkIdTimeout((uint8_t)aTimeout); + instance.GetThreadNetif().GetMle().SetNetworkIdTimeout(aTimeout); } uint8_t otThreadGetRouterUpgradeThreshold(otInstance *aInstance) diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index 199ef07b1..bd2099ead 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -121,7 +121,7 @@ int Dtls::HandleMbedtlsEntropyPoll(void *aData, unsigned char *aOutput, size_t a otError error; int rval = 0; - error = otPlatRandomGetTrue((uint8_t *)aOutput, (uint16_t)aInLen); + error = otPlatRandomGetTrue(static_cast(aOutput), static_cast(aInLen)); SuccessOrExit(error); if (aOutLen != NULL) @@ -413,17 +413,19 @@ int Dtls::SetApplicationCoapSecureKeys(void) #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED if (mCaChainSrc != NULL) { - rval = mbedtls_x509_crt_parse(&mCaChain, (const unsigned char *)mCaChainSrc, (size_t)mCaChainLength); + rval = mbedtls_x509_crt_parse(&mCaChain, static_cast(mCaChainSrc), + static_cast(mCaChainLength)); VerifyOrExit(rval == 0); mbedtls_ssl_conf_ca_chain(&mConf, &mCaChain, NULL); } if (mOwnCertSrc != NULL && mPrivateKeySrc != NULL) { - rval = mbedtls_x509_crt_parse(&mOwnCert, (const unsigned char *)mOwnCertSrc, (size_t)mOwnCertLength); + rval = mbedtls_x509_crt_parse(&mOwnCert, static_cast(mOwnCertSrc), + static_cast(mOwnCertLength)); VerifyOrExit(rval == 0); - rval = mbedtls_pk_parse_key(&mPrivateKey, (const unsigned char *)mPrivateKeySrc, (size_t)mPrivateKeyLength, - NULL, 0); + rval = mbedtls_pk_parse_key(&mPrivateKey, static_cast(mPrivateKeySrc), + static_cast(mPrivateKeyLength), NULL, 0); VerifyOrExit(rval == 0); rval = mbedtls_ssl_conf_own_cert(&mConf, &mOwnCert, &mPrivateKey); VerifyOrExit(rval == 0); @@ -433,8 +435,8 @@ int Dtls::SetApplicationCoapSecureKeys(void) case MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8: #ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED - rval = mbedtls_ssl_conf_psk(&mConf, (unsigned char *)mPreSharedKey, mPreSharedKeyLength, - (unsigned char *)mPreSharedKeyIdentity, mPreSharedKeyIdLength); + rval = mbedtls_ssl_conf_psk(&mConf, static_cast(mPreSharedKey), mPreSharedKeyLength, + static_cast(mPreSharedKeyIdentity), mPreSharedKeyIdLength); VerifyOrExit(rval == 0); #endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED break; @@ -706,7 +708,7 @@ int Dtls::HandleMbedtlsReceive(unsigned char *aBuf, size_t aLength) aLength = mReceiveLength; } - rval = (int)mReceiveMessage->Read(mReceiveOffset, (uint16_t)aLength, aBuf); + rval = mReceiveMessage->Read(mReceiveOffset, static_cast(aLength), aBuf); mReceiveOffset += static_cast(rval); mReceiveLength -= static_cast(rval); diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 4675e5974..991b5e868 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -1576,7 +1576,7 @@ template <> otError NcpBase::HandlePropertySet(void) VerifyOrExit(HasOnly1BitSet(mScanChannelMask), error = OT_ERROR_INVALID_ARGS); scanChannel = IndexOfMSB(mScanChannelMask); - mCurScanChannel = (int8_t)scanChannel; + mCurScanChannel = static_cast(scanChannel); error = otLinkRawEnergyScan(mInstance, scanChannel, mScanPeriod, LinkRawEnergyScanDone); } diff --git a/src/ncp/spinel.c b/src/ncp/spinel.c index 8ac57dec1..32c760ef8 100644 --- a/src/ncp/spinel.c +++ b/src/ncp/spinel.c @@ -777,7 +777,7 @@ static spinel_ssize_t spinel_datatype_vpack_(uint8_t * data_ptr, case SPINEL_DATATYPE_INT64_C: case SPINEL_DATATYPE_UINT64_C: { - uint64_t arg = (uint64_t)va_arg(args->obj, uint64_t); + uint64_t arg = va_arg(args->obj, uint64_t); ret += sizeof(uint64_t);