mirror of
https://github.com/NixOS/patchelf.git
synced 2025-10-23 18:18:31 +08:00
replace for loop with any_of
Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
@@ -79,9 +79,7 @@ static std::vector<std::string> splitColonDelimitedString(const char * s)
|
|||||||
|
|
||||||
static bool hasAllowedPrefix(const std::string & s, const std::vector<std::string> & allowedPrefixes)
|
static bool hasAllowedPrefix(const std::string & s, const std::vector<std::string> & allowedPrefixes)
|
||||||
{
|
{
|
||||||
for (auto & i : allowedPrefixes)
|
return std::any_of(allowedPrefixes.begin(), allowedPrefixes.end(), [&](const std::string & i) { return !s.compare(0, i.size(), i); });
|
||||||
if (!s.compare(0, i.size(), i)) return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -787,10 +785,8 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
|
|||||||
|
|
||||||
/* When normalizing note segments we will in the worst case be adding
|
/* When normalizing note segments we will in the worst case be adding
|
||||||
1 program header for each SHT_NOTE section. */
|
1 program header for each SHT_NOTE section. */
|
||||||
unsigned int num_notes = 0;
|
unsigned int num_notes = std::count_if(shdrs.begin(), shdrs.end(), [this](Elf_Shdr shdr) { return rdi(shdr.sh_type) == SHT_NOTE; });
|
||||||
for (const auto & shdr : shdrs)
|
;
|
||||||
if (rdi(shdr.sh_type) == SHT_NOTE)
|
|
||||||
num_notes++;
|
|
||||||
|
|
||||||
/* Because we're adding a new section header, we're necessarily increasing
|
/* Because we're adding a new section header, we're necessarily increasing
|
||||||
the size of the program header table. This can cause the first section
|
the size of the program header table. This can cause the first section
|
||||||
@@ -992,11 +988,7 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
|
|||||||
one of them has to be replaced. */
|
one of them has to be replaced. */
|
||||||
|
|
||||||
/* We don't need to do anything if no note segments were replaced. */
|
/* We don't need to do anything if no note segments were replaced. */
|
||||||
bool replaced_note = false;
|
bool replaced_note = std::any_of(replacedSections.begin(), replacedSections.end(), [this](std::pair<const std::string, std::string> & i) { return rdi(findSection(i.first).sh_type) == SHT_NOTE; });
|
||||||
for (const auto & i : replacedSections) {
|
|
||||||
if (rdi(findSection(i.first).sh_type) == SHT_NOTE)
|
|
||||||
replaced_note = true;
|
|
||||||
}
|
|
||||||
if (!replaced_note) return;
|
if (!replaced_note) return;
|
||||||
|
|
||||||
size_t orig_count = phdrs.size();
|
size_t orig_count = phdrs.size();
|
||||||
@@ -1604,8 +1596,7 @@ void ElfFile<ElfFileParamNames>::addNeeded(const std::set<std::string> & libs)
|
|||||||
auto shdrDynStr = findSection(".dynstr");
|
auto shdrDynStr = findSection(".dynstr");
|
||||||
|
|
||||||
/* add all new libs to the dynstr string table */
|
/* add all new libs to the dynstr string table */
|
||||||
unsigned int length = 0;
|
unsigned int length = std::count_if(libs.begin(), libs.end(), [](const std::string & lib) { return lib.size() + 1; });
|
||||||
for (auto & i : libs) length += i.size() + 1;
|
|
||||||
|
|
||||||
std::string & newDynStr = replaceSection(".dynstr",
|
std::string & newDynStr = replaceSection(".dynstr",
|
||||||
rdi(shdrDynStr.sh_size) + length + 1);
|
rdi(shdrDynStr.sh_size) + length + 1);
|
||||||
|
Reference in New Issue
Block a user