NetworkPkg/DnsDxe: Refactor answer loop to for in ParseDnsResponse

The answer section loop in ParseDnsResponse() iterated a counter
AnswerSectionNum from 0 to DnsHeader->AnswersNum using a while loop
with a manual increment at the bottom. Convert it to an equivalent
for loop to make the initialization, condition, and increment
explicit.

Also replace the unconditional Status = EFI_NOT_FOUND assignment
before the loop with a conditional that only sets it when the loop
is never entered (DnsHeader->AnswersNum == 0). ParseDnsResponse()
initializes Status to EFI_SUCCESS at function entry, and the loop
body always overwrites Status, so the pre-assignment was dead code
in the common case. The conditional form makes the intent explicit:
EFI_NOT_FOUND is only the result when there are no answer records.

Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
Cc: Zachary Clark-williams <zachary.clark-williams@intel.com>

Signed-off-by: abuthahirm <abuthahirm@ami.com>
This commit is contained in:
abuthahirm 2026-03-25 19:44:37 +05:30 committed by mergify[bot]
parent ccc95703cd
commit 6d4e973807

View file

@ -1165,10 +1165,9 @@ ParseDnsResponse (
Dns4TokenEntry = NULL;
Dns6TokenEntry = NULL;
IpCount = 0;
RRCount = 0;
AnswerSectionNum = 0;
CNameTtl = 0;
IpCount = 0;
RRCount = 0;
CNameTtl = 0;
HostAddr4 = NULL;
HostAddr6 = NULL;
@ -1378,8 +1377,6 @@ ParseDnsResponse (
}
}
Status = EFI_NOT_FOUND;
//
// Get Answer name
//
@ -1388,7 +1385,11 @@ ParseDnsResponse (
//
// Processing AnswerSection.
//
while (AnswerSectionNum < DnsHeader->AnswersNum) {
if (DnsHeader->AnswersNum == 0) {
Status = EFI_NOT_FOUND;
}
for (AnswerSectionNum = 0; AnswerSectionNum < DnsHeader->AnswersNum; AnswerSectionNum++) {
//
// Check whether the remaining packet length is available or not.
//
@ -1635,7 +1636,6 @@ ParseDnsResponse (
// Find next one
//
AnswerName = (CHAR8 *)AnswerSection + sizeof (*AnswerSection) + AnswerSection->DataLength;
AnswerSectionNum++;
}
if (Instance->Service->IpVersion == IP_VERSION_4) {