[debug] adding SuccessOrAssert() helper macro (#7083)

This commit adds a new macro `SuccessOrAssert()` which checks a given
status value against zero (zero status indicates success or no error)
and `OT_ASSERT()` if it is not. This helper macro is then used by
other modules where we want to assert that some method/function is
not returning an error.
This commit is contained in:
Abtin Keshavarzian
2021-10-20 17:01:25 -07:00
committed by GitHub
parent 50285e4c53
commit d2c0dac4ba
23 changed files with 80 additions and 192 deletions
+1 -7
View File
@@ -100,17 +100,11 @@ Error CoapSecure::Connect(const Ip6::SockAddr &aSockAddr, ConnectedCallback aCal
void CoapSecure::SetPsk(const MeshCoP::JoinerPskd &aPskd)
{
Error error;
OT_UNUSED_VARIABLE(error);
static_assert(static_cast<uint16_t>(MeshCoP::JoinerPskd::kMaxLength) <=
static_cast<uint16_t>(MeshCoP::Dtls::kPskMaxLength),
"The maximum length of DTLS PSK is smaller than joiner PSKd");
error = mDtls.SetPsk(reinterpret_cast<const uint8_t *>(aPskd.GetAsCString()), aPskd.GetLength());
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(mDtls.SetPsk(reinterpret_cast<const uint8_t *>(aPskd.GetAsCString()), aPskd.GetLength()));
}
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
+16
View File
@@ -92,4 +92,20 @@
#endif // OPENTHREAD_CONFIG_ASSERT_ENABLE
/**
* This macro checks a given status (which is expected to be successful) against zero (0) which indicates success,
* and `OT_ASSERT()` if it is not.
*
* @param[in] aStatus A scalar status to be evaluated against zero (0).
*
*/
#define SuccessOrAssert(aStatus) \
do \
{ \
if ((aStatus) != 0) \
{ \
OT_ASSERT(false); \
} \
} while (false)
#endif // DEBUG_HPP_
+2 -7
View File
@@ -54,9 +54,6 @@ RandomManager::CryptoCtrDrbg RandomManager::sCtrDrbg;
RandomManager::RandomManager(void)
{
uint32_t seed;
Error error;
OT_UNUSED_VARIABLE(error);
OT_ASSERT(sInitCount < 0xffff);
@@ -66,11 +63,9 @@ RandomManager::RandomManager(void)
sEntropy.Init();
sCtrDrbg.Init();
error = Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Random::Crypto::FillBuffer(reinterpret_cast<uint8_t *>(&seed), sizeof(seed)));
#else
error = otPlatEntropyGet(reinterpret_cast<uint8_t *>(&seed), sizeof(seed));
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(otPlatEntropyGet(reinterpret_cast<uint8_t *>(&seed), sizeof(seed)));
#endif
sPrng.Init(seed);
+4 -15
View File
@@ -40,35 +40,24 @@ namespace Crypto {
AesEcb::AesEcb(void)
{
Error err = kErrorNone;
mContext.mContext = mContextStorage;
mContext.mContextSize = sizeof(mContextStorage);
err = otPlatCryptoAesInit(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoAesInit(&mContext));
}
void AesEcb::SetKey(const Key &aKey)
{
Error err = otPlatCryptoAesSetKey(&mContext, &aKey);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoAesSetKey(&mContext, &aKey));
}
void AesEcb::Encrypt(const uint8_t aInput[kBlockSize], uint8_t aOutput[kBlockSize])
{
Error err = otPlatCryptoAesEncrypt(&mContext, aInput, aOutput);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoAesEncrypt(&mContext, aInput, aOutput));
}
AesEcb::~AesEcb(void)
{
Error err = otPlatCryptoAesFree(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoAesFree(&mContext));
}
} // namespace Crypto
+4 -16
View File
@@ -45,36 +45,24 @@ namespace Crypto {
HkdfSha256::HkdfSha256(void)
{
Error err = kErrorNone;
mContext.mContext = mContextStorage;
mContext.mContextSize = sizeof(mContextStorage);
err = otPlatCryptoHkdfInit(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHkdfInit(&mContext));
}
HkdfSha256::~HkdfSha256(void)
{
Error err = otPlatCryptoHkdfDeinit(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHkdfDeinit(&mContext));
}
void HkdfSha256::Extract(const uint8_t *aSalt, uint16_t aSaltLength, const Key &aInputKey)
{
Error err = otPlatCryptoHkdfExtract(&mContext, aSalt, aSaltLength, &aInputKey);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHkdfExtract(&mContext, aSalt, aSaltLength, &aInputKey));
}
void HkdfSha256::Expand(const uint8_t *aInfo, uint16_t aInfoLength, uint8_t *aOutputKey, uint16_t aOutputKeyLength)
{
Error err = otPlatCryptoHkdfExpand(&mContext, aInfo, aInfoLength, aOutputKey, aOutputKeyLength);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHkdfExpand(&mContext, aInfo, aInfoLength, aOutputKey, aOutputKeyLength));
}
} // namespace Crypto
+5 -17
View File
@@ -41,42 +41,30 @@ namespace Crypto {
HmacSha256::HmacSha256(void)
{
Error err = kErrorNone;
mContext.mContext = mContextStorage;
mContext.mContextSize = sizeof(mContextStorage);
err = otPlatCryptoHmacSha256Init(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHmacSha256Init(&mContext));
}
HmacSha256::~HmacSha256(void)
{
Error err = otPlatCryptoHmacSha256Deinit(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHmacSha256Deinit(&mContext));
}
void HmacSha256::Start(const Key &aKey)
{
Error err = otPlatCryptoHmacSha256Start(&mContext, &aKey);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHmacSha256Start(&mContext, &aKey));
}
void HmacSha256::Update(const void *aBuf, uint16_t aBufLength)
{
Error err = otPlatCryptoHmacSha256Update(&mContext, aBuf, aBufLength);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHmacSha256Update(&mContext, aBuf, aBufLength));
}
void HmacSha256::Finish(Hash &aHash)
{
Error err = otPlatCryptoHmacSha256Finish(&mContext, aHash.m8, Hash::kSize);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoHmacSha256Finish(&mContext, aHash.m8, Hash::kSize));
}
void HmacSha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
+6 -18
View File
@@ -42,35 +42,24 @@ namespace Crypto {
Sha256::Sha256(void)
{
Error err = kErrorNone;
mContext.mContext = mContextStorage;
mContext.mContextSize = sizeof(mContextStorage);
err = otPlatCryptoSha256Init(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoSha256Init(&mContext));
}
Sha256::~Sha256(void)
{
Error err = otPlatCryptoSha256Deinit(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoSha256Deinit(&mContext));
}
void Sha256::Start(void)
{
Error err = otPlatCryptoSha256Start(&mContext);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoSha256Start(&mContext));
}
void Sha256::Update(const void *aBuf, uint16_t aBufLength)
{
Error err = otPlatCryptoSha256Update(&mContext, aBuf, aBufLength);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoSha256Update(&mContext, aBuf, aBufLength));
}
void Sha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
@@ -88,9 +77,8 @@ void Sha256::Update(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
void Sha256::Finish(Hash &aHash)
{
Error err = otPlatCryptoSha256Finish(&mContext, aHash.m8, Hash::kSize);
OT_ASSERT(err == kErrorNone);
OT_UNUSED_VARIABLE(err);
SuccessOrAssert(otPlatCryptoSha256Finish(&mContext, aHash.m8, Hash::kSize));
}
} // namespace Crypto
} // namespace ot
+2 -8
View File
@@ -46,9 +46,8 @@ Error Key::ExtractKey(uint8_t *aKeyBuffer, uint16_t &aKeyLength) const
OT_ASSERT(IsKeyRef());
error = Crypto::Storage::ExportKey(GetKeyRef(), aKeyBuffer, aKeyLength, readKeyLength);
SuccessOrAssert(Crypto::Storage::ExportKey(GetKeyRef(), aKeyBuffer, aKeyLength, readKeyLength));
OT_ASSERT(error == kErrorNone);
VerifyOrExit(readKeyLength <= aKeyLength, error = kErrorNoBufs);
aKeyLength = static_cast<uint16_t>(readKeyLength);
@@ -65,14 +64,9 @@ LiteralKey::LiteralKey(const Key &aKey)
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
if (aKey.IsKeyRef())
{
Error error;
mKey = mBuffer;
mLength = sizeof(mBuffer);
error = aKey.ExtractKey(mBuffer, mLength);
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(aKey.ExtractKey(mBuffer, mLength));
}
#endif
}
+2 -7
View File
@@ -273,17 +273,12 @@ void DataPollHandler::HandleSentFrame(const Mac::TxFrame &aFrame, Error aError,
{
uint32_t frameCounter;
uint8_t keyId;
Error error;
error = aFrame.GetFrameCounter(frameCounter);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(aFrame.GetFrameCounter(frameCounter));
aChild.SetIndirectFrameCounter(frameCounter);
error = aFrame.GetKeyId(keyId);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(aFrame.GetKeyId(keyId));
aChild.SetIndirectKeyId(keyId);
OT_UNUSED_VARIABLE(error);
}
ExitNow();
+1 -4
View File
@@ -156,10 +156,7 @@ void Links::Send(TxFrame &aFrame, RadioTypes aRadioTypes)
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
if (aRadioTypes.Contains(kRadioTypeIeee802154))
{
Error error = mSubMac.Send();
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(mSubMac.Send());
}
#endif
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
+1 -5
View File
@@ -511,11 +511,7 @@ public:
void Send(void)
{
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
{
Error error = mSubMac.Send();
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
}
SuccessOrAssert(mSubMac.Send());
#endif
#if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE
mTrel.Send();
+6 -12
View File
@@ -355,18 +355,15 @@ void KeyMaterial::SetFrom(const Key &aKey, bool aIsExportable)
{
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
{
Error error;
KeyRef keyRef = 0;
DestroyKey();
error = Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeAes, Crypto::Storage::kKeyAlgorithmAesEcb,
(aIsExportable ? Crypto::Storage::kUsageExport : 0) |
Crypto::Storage::kUsageEncrypt | Crypto::Storage::kUsageDecrypt,
Crypto::Storage::kTypeVolatile, aKey.GetBytes(), Key::kSize);
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeAes,
Crypto::Storage::kKeyAlgorithmAesEcb,
(aIsExportable ? Crypto::Storage::kUsageExport : 0) |
Crypto::Storage::kUsageEncrypt | Crypto::Storage::kUsageDecrypt,
Crypto::Storage::kTypeVolatile, aKey.GetBytes(), Key::kSize));
SetKeyRef(keyRef);
}
@@ -383,12 +380,9 @@ void KeyMaterial::ExtractKey(Key &aKey)
if (Crypto::Storage::IsKeyRefValid(GetKeyRef()))
{
Error error;
size_t keySize;
error = Crypto::Storage::ExportKey(GetKeyRef(), aKey.m8, Key::kSize, keySize);
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(Crypto::Storage::ExportKey(GetKeyRef(), aKey.m8, Key::kSize, keySize));
}
#else
aKey = GetKey();
+5 -6
View File
@@ -184,7 +184,7 @@ Error SubMac::Enable(void)
SetState(kStateSleep);
exit:
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(error);
return error;
}
@@ -455,8 +455,7 @@ void SubMac::BeginTransmit(void)
if ((mRadioCaps & OT_RADIO_CAPS_SLEEP_TO_TX) == 0)
{
error = Get<Radio>().Receive(mTransmitFrame.GetChannel());
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Get<Radio>().Receive(mTransmitFrame.GetChannel()));
}
SetState(kStateTransmit);
@@ -474,7 +473,8 @@ void SubMac::BeginTransmit(void)
mTransmitFrame.mInfo.mTxInfo.mTxDelayBaseTime = 0;
error = Get<Radio>().Transmit(mTransmitFrame);
}
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(error);
exit:
return;
@@ -644,8 +644,7 @@ Error SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration)
}
else if (ShouldHandleEnergyScan())
{
error = Get<Radio>().Receive(aScanChannel);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Get<Radio>().Receive(aScanChannel));
SetState(kStateEnergyScan);
mEnergyScanMaxRssi = kInvalidRssiValue;
+1 -7
View File
@@ -187,13 +187,7 @@ bool InterfaceIdentifier::IsReservedSubnetAnycast(void) const
void InterfaceIdentifier::GenerateRandom(void)
{
Error error;
OT_UNUSED_VARIABLE(error);
error = Random::Crypto::FillBuffer(mFields.m8, kSize);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Random::Crypto::FillBuffer(mFields.m8, kSize));
}
void InterfaceIdentifier::SetBytes(const uint8_t *aBuffer)
+1 -4
View File
@@ -427,10 +427,7 @@ void Mpl::Metadata::ReadFrom(const Message &aMessage)
void Mpl::Metadata::RemoveFrom(Message &aMessage) const
{
Error error = aMessage.SetLength(aMessage.GetLength() - sizeof(*this));
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
}
void Mpl::Metadata::UpdateIn(Message &aMessage) const
+2 -6
View File
@@ -226,8 +226,7 @@ exit:
void Netif::SubscribeAllRoutersMulticast(void)
{
Error error = kErrorNone;
MulticastAddress *prev = nullptr;
MulticastAddress *prev = nullptr;
MulticastAddress &linkLocalAllRoutersAddress =
static_cast<MulticastAddress &>(AsNonConst(kLinkLocalAllRoutersMulticastAddress));
MulticastAddress &linkLocalAllNodesAddress =
@@ -235,13 +234,10 @@ void Netif::SubscribeAllRoutersMulticast(void)
MulticastAddress &realmLocalAllRoutersAddress =
static_cast<MulticastAddress &>(AsNonConst(kRealmLocalAllRoutersMulticastAddress));
error = mMulticastAddresses.Find(linkLocalAllNodesAddress, prev);
// This method MUST be called after `SubscribeAllNodesMulticast()`
// Ensure that the `LinkLocalAll` was found on the list.
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(mMulticastAddresses.Find(linkLocalAllNodesAddress, prev));
// The tail of multicast address linked list contains the
// fixed addresses. We either have a chain of five addresses
+1 -4
View File
@@ -426,10 +426,7 @@ public:
*/
void ReadFrom(const Message &aMessage)
{
Error error = aMessage.Read(aMessage.GetLength() - sizeof(*this), *this);
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(aMessage.Read(aMessage.GetLength() - sizeof(*this), *this));
}
/**
+3 -11
View File
@@ -37,13 +37,8 @@ namespace ot {
void Radio::Init(void)
{
#if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE
Error error = OT_ERROR_NONE;
OT_UNUSED_VARIABLE(error);
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
error = EnableCsl(0, Mac::kShortAddrInvalid, nullptr);
OT_ASSERT(error == OT_ERROR_NONE);
SuccessOrAssert(EnableCsl(0, Mac::kShortAddrInvalid, nullptr));
#endif
EnableSrcMatch(false);
@@ -52,11 +47,8 @@ void Radio::Init(void)
if (IsEnabled())
{
error = Sleep();
OT_ASSERT(error == OT_ERROR_NONE);
error = Disable();
OT_ASSERT(error == OT_ERROR_NONE);
SuccessOrAssert(Sleep());
SuccessOrAssert(Disable());
}
SetPanId(Mac::kPanIdBroadcast);
+9 -19
View File
@@ -523,13 +523,10 @@ void KeyManager::GetNetworkKey(NetworkKey &aNetworkKey) const
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
if (Crypto::Storage::IsKeyRefValid(mNetworkKeyRef))
{
Error error = kErrorNone;
size_t keyLen;
error = Crypto::Storage::ExportKey(mNetworkKeyRef, aNetworkKey.m8, NetworkKey::kSize, keyLen);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Crypto::Storage::ExportKey(mNetworkKeyRef, aNetworkKey.m8, NetworkKey::kSize, keyLen));
OT_ASSERT(keyLen == NetworkKey::kSize);
OT_UNUSED_VARIABLE(error);
}
else
{
@@ -545,13 +542,10 @@ void KeyManager::GetPskc(Pskc &aPskc) const
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
if (Crypto::Storage::IsKeyRefValid(mPskcRef))
{
Error error = kErrorNone;
size_t keyLen;
error = Crypto::Storage::ExportKey(mPskcRef, aPskc.m8, Pskc::kSize, keyLen);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Crypto::Storage::ExportKey(mPskcRef, aPskc.m8, Pskc::kSize, keyLen));
OT_ASSERT(keyLen == Pskc::kSize);
OT_UNUSED_VARIABLE(error);
}
else
{
@@ -566,7 +560,6 @@ void KeyManager::GetPskc(Pskc &aPskc) const
void KeyManager::StoreNetworkKey(const NetworkKey &aNetworkKey, bool aOverWriteExisting)
{
Error error;
NetworkKeyRef keyRef;
keyRef = kNetworkKeyPsaItsOffset;
@@ -584,10 +577,10 @@ void KeyManager::StoreNetworkKey(const NetworkKey &aNetworkKey, bool aOverWriteE
Crypto::Storage::DestroyKey(keyRef);
error = Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeHmac, Crypto::Storage::kKeyAlgorithmHmacSha256,
Crypto::Storage::kUsageSignHash | Crypto::Storage::kUsageExport,
Crypto::Storage::kTypePersistent, aNetworkKey.m8, NetworkKey::kSize);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeHmac,
Crypto::Storage::kKeyAlgorithmHmacSha256,
Crypto::Storage::kUsageSignHash | Crypto::Storage::kUsageExport,
Crypto::Storage::kTypePersistent, aNetworkKey.m8, NetworkKey::kSize));
exit:
if (mNetworkKeyRef != keyRef)
@@ -601,15 +594,12 @@ exit:
void KeyManager::StorePskc(const Pskc &aPskc)
{
PskcRef keyRef = kPskcPsaItsOffset;
Error error = kErrorNone;
Crypto::Storage::DestroyKey(keyRef);
error = Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeRaw, Crypto::Storage::kKeyAlgorithmVendor,
Crypto::Storage::kUsageExport, Crypto::Storage::kTypePersistent, aPskc.m8,
Pskc::kSize);
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(Crypto::Storage::ImportKey(keyRef, Crypto::Storage::kKeyTypeRaw,
Crypto::Storage::kKeyAlgorithmVendor, Crypto::Storage::kUsageExport,
Crypto::Storage::kTypePersistent, aPskc.m8, Pskc::kSize));
if (mPskcRef != keyRef)
{
+1 -5
View File
@@ -775,9 +775,6 @@ start:
maxPayloadLength - headerLength - Lowpan::FragmentHeader::kFirstFragmentHeaderSize);
uint8_t hcLength;
Mac::Address meshSource, meshDest;
Error error;
OT_UNUSED_VARIABLE(error);
if (aAddMeshHeader)
{
@@ -790,8 +787,7 @@ start:
meshDest = aMacDest;
}
error = Get<Lowpan::Lowpan>().Compress(aMessage, meshSource, meshDest, buffer);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Get<Lowpan::Lowpan>().Compress(aMessage, meshSource, meshDest, buffer));
hcLength = static_cast<uint8_t>(buffer.GetWritePointer() - payload);
headerLength += hcLength;
+2 -6
View File
@@ -1307,9 +1307,7 @@ Error Mle::AppendAddressRegistration(Message &aMessage, AddressRegistrationMode
if (Get<ThreadNetif>().HasUnicastAddress(domainUnicastAddress))
{
error = Get<NetworkData::Leader>().GetContext(domainUnicastAddress, context);
OT_ASSERT(error == kErrorNone);
SuccessOrAssert(Get<NetworkData::Leader>().GetContext(domainUnicastAddress, context));
// Prioritize DUA, compressed entry
entry.SetContextId(context.mContextId);
@@ -4611,9 +4609,7 @@ void Mle::DelayedResponseMetadata::ReadFrom(const Message &aMessage)
void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const
{
Error error = aMessage.SetLength(aMessage.GetLength() - sizeof(*this));
OT_ASSERT(error == kErrorNone);
OT_UNUSED_VARIABLE(error);
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
}
} // namespace Mle
+3 -4
View File
@@ -1219,8 +1219,7 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader)
if (mDecoder.GetRemainingLengthInStruct() > 0)
{
error = mDecoder.ReadUint8(reset_type);
OT_ASSERT(error == OT_ERROR_NONE);
SuccessOrAssert(error = mDecoder.ReadUint8(reset_type));
}
#if OPENTHREAD_RADIO
@@ -1235,8 +1234,8 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader)
ResetCounters();
error = WriteLastStatusFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_STATUS_RESET_POWER_ON);
OT_ASSERT(error == OT_ERROR_NONE);
SuccessOrAssert(
error = WriteLastStatusFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_STATUS_RESET_POWER_ON));
}
else
#endif
+2 -4
View File
@@ -3771,8 +3771,7 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_SRP_CLIENT_HOST_NAME>
SuccessOrExit(error = otSrpClientSetHostName(mInstance, name));
strcpy(hostNameBuffer, name);
error = otSrpClientSetHostName(mInstance, hostNameBuffer);
OT_ASSERT(error == OT_ERROR_NONE);
SuccessOrAssert(error = otSrpClientSetHostName(mInstance, hostNameBuffer));
exit:
return error;
@@ -3820,8 +3819,7 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_SRP_CLIENT_HOST_ADDRE
memcpy(hostAddressArray, addresses, sizeof(addresses));
error = otSrpClientSetHostAddresses(mInstance, hostAddressArray, numAddresses);
OT_ASSERT(error == OT_ERROR_NONE);
SuccessOrAssert(error = otSrpClientSetHostAddresses(mInstance, hostAddressArray, numAddresses));
exit:
return error;