Fix an issue caused by variable re-declaration in inner scope

Since btf is declared in inner scope, btf is null in outer scope and BTF
was always disabled.

This CL also makes NetBpfLoad buildable with -Wshadow flag

Test: adb log | grep NetBpfLoad
Change-Id: I511f21a3620ccfdadd797786e087d0d142c816ed
This commit is contained in:
Motomu Utsumi 2025-03-21 15:13:00 +09:00
commit 62b1c88367

View file

@ -556,9 +556,9 @@ static int readCodeSections(ifstream& elfFile, vector<codeSection>& cs) {
vector<string> csSymNames;
ret = getSectionSymNames(elfFile, oldName, csSymNames, STT_FUNC);
if (ret || !csSymNames.size()) return ret;
for (size_t i = 0; i < progDefNames.size(); ++i) {
if (!progDefNames[i].compare(csSymNames[0] + "_def")) {
cs_temp.prog_def = pd[i];
for (size_t j = 0; j < progDefNames.size(); ++j) {
if (!progDefNames[j].compare(csSymNames[0] + "_def")) {
cs_temp.prog_def = pd[j];
break;
}
}
@ -865,7 +865,7 @@ static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>&
ALOGE("Failed to read .BTF section, ret:%d", ret);
return ret;
}
struct btf *btf = btf__new(btfData.data(), btfData.size());
btf = btf__new(btfData.data(), btfData.size());
if (btf == NULL) {
ALOGE("btf__new failed, errno: %d", errno);
return -errno;