[ip6] reduce scope of local vars in SelectSourceAddress() (#4377)

This commit is contained in:
Jonathan Hui
2019-12-04 08:22:49 -08:00
parent 0b49ea2b83
commit d12246d2ee
+9 -10
View File
@@ -1298,20 +1298,16 @@ exit:
const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
{
Address * destination = &aMessageInfo.GetPeerAddr();
const NetifUnicastAddress *rvalAddr = NULL;
const Address * candidateAddr;
uint8_t rvalPrefixMatched = 0;
Address * destination = &aMessageInfo.GetPeerAddr();
uint8_t destinationScope = destination->GetScope();
const NetifUnicastAddress *rvalAddr = NULL;
uint8_t rvalPrefixMatched = 0;
for (const NetifUnicastAddress *addr = Get<ThreadNetif>().GetUnicastAddresses(); addr; addr = addr->GetNext())
{
uint8_t overrideScope;
uint8_t candidatePrefixMatched;
candidateAddr = &addr->GetAddress();
candidatePrefixMatched = destination->PrefixMatch(*candidateAddr);
overrideScope = (candidatePrefixMatched >= addr->mPrefixLength) ? addr->GetScope() : destinationScope;
const Address *candidateAddr = &addr->GetAddress();
uint8_t candidatePrefixMatched;
uint8_t overrideScope;
if (candidateAddr->IsAnycastRoutingLocator())
{
@@ -1319,6 +1315,9 @@ const NetifUnicastAddress *Ip6::SelectSourceAddress(MessageInfo &aMessageInfo)
continue;
}
candidatePrefixMatched = destination->PrefixMatch(*candidateAddr);
overrideScope = (candidatePrefixMatched >= addr->mPrefixLength) ? addr->GetScope() : destinationScope;
if (rvalAddr == NULL)
{
// Rule 0: Prefer any address