[nexus] clear OnMeshPrefixConfig before use in tests (#12501)

This commit ensures that the NetworkData::OnMeshPrefixConfig structure
is cleared using config.Clear() before it is used in Nexus tests.

Since OnMeshPrefixConfig is a local variable on the stack, its fields
can contain garbage values if not explicitly initialized. The core
validity check OnMeshPrefixConfig::IsValid() fails if both mDhcp and
mSlaac are set to true, which can happen with uninitialized memory.

Updated tests:
- tests/nexus/test_6_3_2.cpp: Fixed RunTest6_3_2.
- tests/nexus/test_5_6_1.cpp: Fixed RunTest5_6_1.
This commit is contained in:
Jonathan Hui
2026-02-19 19:33:52 -06:00
committed by GitHub
parent f277297514
commit be867deea6
2 changed files with 3 additions and 0 deletions
+1
View File
@@ -139,6 +139,7 @@ void Test5_6_1(void)
{
NetworkData::OnMeshPrefixConfig config;
config.Clear();
SuccessOrQuit(config.GetPrefix().FromString(prefixInfo.mPrefix));
config.mStable = prefixInfo.mIsStable;
config.mOnMesh = true;
+2
View File
@@ -153,6 +153,7 @@ void RunTest6_3_2(Topology aTopology, const char *aJsonFile)
{
NetworkData::OnMeshPrefixConfig config;
config.Clear();
SuccessOrQuit(config.GetPrefix().FromString("2001::/64"));
config.mStable = true;
config.mOnMesh = true;
@@ -237,6 +238,7 @@ void RunTest6_3_2(Topology aTopology, const char *aJsonFile)
{
NetworkData::OnMeshPrefixConfig config;
config.Clear();
SuccessOrQuit(config.GetPrefix().FromString("2002::/64"));
config.mStable = true;
config.mOnMesh = true;