From 62b1c8836735463e48cd5aed4d4e5f35208bf9ac Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Fri, 21 Mar 2025 15:13:00 +0900 Subject: [PATCH] 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 --- bpf/loader/NetBpfLoad.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bpf/loader/NetBpfLoad.cpp b/bpf/loader/NetBpfLoad.cpp index 4c47f83bbf..dc0a548878 100644 --- a/bpf/loader/NetBpfLoad.cpp +++ b/bpf/loader/NetBpfLoad.cpp @@ -556,9 +556,9 @@ static int readCodeSections(ifstream& elfFile, vector& cs) { vector 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& 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;