Skip to content

Commit 81c64dd

Browse files
committed
Declare more read-only functions const
1 parent 00d1e82 commit 81c64dd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/patchelf.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ std::string ElfFile<ElfFileParamNames>::getSectionName(const Elf_Shdr & shdr) co
535535

536536

537537
template<ElfFileParams>
538-
Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sectionName)
538+
const Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sectionName) const
539539
{
540540
auto shdr = tryFindSectionHeader(sectionName);
541541
if (!shdr) {
@@ -549,7 +549,7 @@ Elf_Shdr & ElfFile<ElfFileParamNames>::findSectionHeader(const SectionName & sec
549549

550550

551551
template<ElfFileParams>
552-
std::optional<std::reference_wrapper<Elf_Shdr>> ElfFile<ElfFileParamNames>::tryFindSectionHeader(const SectionName & sectionName)
552+
std::optional<std::reference_wrapper<const Elf_Shdr>> ElfFile<ElfFileParamNames>::tryFindSectionHeader(const SectionName & sectionName) const
553553
{
554554
auto i = getSectionIndex(sectionName);
555555
if (i)
@@ -602,7 +602,7 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
602602
clobbering previously written new section contents. */
603603
for (auto & i : replacedSections) {
604604
const std::string & sectionName = i.first;
605-
Elf_Shdr & shdr = findSectionHeader(sectionName);
605+
const Elf_Shdr & shdr = findSectionHeader(sectionName);
606606
if (rdi(shdr.sh_type) != SHT_NOBITS)
607607
memset(fileContents->data() + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
608608
}
@@ -1190,10 +1190,10 @@ static void setSubstr(std::string & s, unsigned int pos, const std::string & t)
11901190

11911191

11921192
template<ElfFileParams>
1193-
std::string ElfFile<ElfFileParamNames>::getInterpreter()
1193+
std::string ElfFile<ElfFileParamNames>::getInterpreter() const
11941194
{
11951195
auto shdr = findSectionHeader(".interp");
1196-
return std::string((char *) fileContents->data() + rdi(shdr.sh_offset), rdi(shdr.sh_size) - 1);
1196+
return std::string((const char *) fileContents->data() + rdi(shdr.sh_offset), rdi(shdr.sh_size) - 1);
11971197
}
11981198

11991199
template<ElfFileParams>
@@ -1776,13 +1776,13 @@ void ElfFile<ElfFileParamNames>::addNeeded(const std::set<std::string> & libs)
17761776
}
17771777

17781778
template<ElfFileParams>
1779-
void ElfFile<ElfFileParamNames>::printNeededLibs() // const
1779+
void ElfFile<ElfFileParamNames>::printNeededLibs() const
17801780
{
17811781
const auto shdrDynamic = findSectionHeader(".dynamic");
17821782
const auto shdrDynStr = findSectionHeader(".dynstr");
1783-
const char *strTab = (char *)fileContents->data() + rdi(shdrDynStr.sh_offset);
1783+
const char *strTab = (const char *)fileContents->data() + rdi(shdrDynStr.sh_offset);
17841784

1785-
const Elf_Dyn *dyn = (Elf_Dyn *) (fileContents->data() + rdi(shdrDynamic.sh_offset));
1785+
const Elf_Dyn *dyn = (const Elf_Dyn *) (fileContents->data() + rdi(shdrDynamic.sh_offset));
17861786

17871787
for (; rdi(dyn->d_tag) != DT_NULL; dyn++) {
17881788
if (rdi(dyn->d_tag) == DT_NEEDED) {

src/patchelf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class ElfFile
8787

8888
[[nodiscard]] std::string getSectionName(const Elf_Shdr & shdr) const;
8989

90-
Elf_Shdr & findSectionHeader(const SectionName & sectionName);
90+
const Elf_Shdr & findSectionHeader(const SectionName & sectionName) const;
9191

92-
[[nodiscard]] std::optional<std::reference_wrapper<Elf_Shdr>> tryFindSectionHeader(const SectionName & sectionName);
92+
[[nodiscard]] std::optional<std::reference_wrapper<const Elf_Shdr>> tryFindSectionHeader(const SectionName & sectionName) const;
9393

9494
[[nodiscard]] unsigned int getSectionIndex(const SectionName & sectionName) const;
9595

@@ -113,7 +113,7 @@ class ElfFile
113113

114114
void rewriteSections(bool force = false);
115115

116-
[[nodiscard]] std::string getInterpreter();
116+
[[nodiscard]] std::string getInterpreter() const;
117117

118118
typedef enum { printOsAbi, replaceOsAbi } osAbiMode;
119119

@@ -137,7 +137,7 @@ class ElfFile
137137

138138
void replaceNeeded(const std::map<std::string, std::string> & libs);
139139

140-
void printNeededLibs() /* should be const */;
140+
void printNeededLibs() const;
141141

142142
void noDefaultLib();
143143

0 commit comments

Comments
 (0)