mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 22:27:47 +00:00
[api] harmonize nullptr assert check of pointer input parameters (#8031)
This commit harmonizes and simplifies the code related to asserting that the OT API pointer parameters are valid and not `nullptr`. `OPENTHREAD_CONFIG_ASSERT_CHECK_API_POINTER_PARAM_FOR_NULL` is added which when used performs assert check on all pointer inputs to APIs. This is either done within `AsCoreType()` when the pointer is converted to its related core type, or by a direct call to newly added macro `AssertPointerIsNotNull()`. Since enabling assert checks on every API parameter can increase code size, this config is disabled by default and it is recommended to use it during debugging only.
This commit is contained in:
@@ -78,8 +78,6 @@ exit:
|
||||
|
||||
otError otThreadGetLeaderRloc(otInstance *aInstance, otIp6Address *aLeaderRloc)
|
||||
{
|
||||
OT_ASSERT(aLeaderRloc != nullptr);
|
||||
|
||||
return AsCoreType(aInstance).Get<Mle::MleRouter>().GetLeaderAddress(AsCoreType(aLeaderRloc));
|
||||
}
|
||||
|
||||
@@ -114,8 +112,6 @@ otError otThreadSetNetworkKey(otInstance *aInstance, const otNetworkKey *aKey)
|
||||
Error error = kErrorNone;
|
||||
Instance &instance = AsCoreType(aInstance);
|
||||
|
||||
OT_ASSERT(aKey != nullptr);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = kErrorInvalidState);
|
||||
|
||||
instance.Get<KeyManager>().SetNetworkKey(AsCoreType(aKey));
|
||||
@@ -297,7 +293,7 @@ otError otThreadBecomeChild(otInstance *aInstance)
|
||||
|
||||
otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo)
|
||||
{
|
||||
OT_ASSERT((aInfo != nullptr) && (aIterator != nullptr));
|
||||
AssertPointerIsNotNull(aIterator);
|
||||
|
||||
return AsCoreType(aInstance).Get<NeighborTable>().GetNextNeighborInfo(*aIterator, AsCoreType(aInfo));
|
||||
}
|
||||
@@ -316,7 +312,7 @@ otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
OT_ASSERT(aLeaderData != nullptr);
|
||||
AssertPointerIsNotNull(aLeaderData);
|
||||
|
||||
VerifyOrExit(AsCoreType(aInstance).Get<Mle::MleRouter>().IsAttached(), error = kErrorDetached);
|
||||
*aLeaderData = AsCoreType(aInstance).Get<Mle::MleRouter>().GetLeaderData();
|
||||
@@ -354,7 +350,7 @@ otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
OT_ASSERT(aParentRssi != nullptr);
|
||||
AssertPointerIsNotNull(aParentRssi);
|
||||
|
||||
*aParentRssi = AsCoreType(aInstance).Get<Mle::MleRouter>().GetParent().GetLinkInfo().GetAverageRss();
|
||||
|
||||
@@ -368,7 +364,7 @@ otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
OT_ASSERT(aLastRssi != nullptr);
|
||||
AssertPointerIsNotNull(aLastRssi);
|
||||
|
||||
*aLastRssi = AsCoreType(aInstance).Get<Mle::MleRouter>().GetParent().GetLinkInfo().GetLastRss();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user