summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2023-02-21 19:40:52 +0100
committerChristian Göttsche <cgzones@googlemail.com>2023-02-21 19:40:52 +0100
commitfbb12a72ad1a98c079597b820364196fcfc512af (patch)
treed00c9fa26a432c76686ad5b497e07bd61b8aea17
parentce5907fc40d5e355872a4288fde3de7586e6e766 (diff)
downloadpatchelf-fbb12a72ad1a98c079597b820364196fcfc512af.tar.gz
Add misc functions annotations
Make the behavior of functions more explicit.
-rw-r--r--src/patchelf.cc8
-rw-r--r--src/patchelf.h32
2 files changed, 20 insertions, 20 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index e91e2ab..1a67158 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -104,7 +104,7 @@ static std::string downcase(std::string s)
why... */
template<ElfFileParams>
template<class I>
-I ElfFile<ElfFileParamNames>::rdi(I i) const
+constexpr I ElfFile<ElfFileParamNames>::rdi(I i) const noexcept
{
I r = 0;
if (littleEndian) {
@@ -131,7 +131,7 @@ static void debug(const char * format, ...)
}
-void fmt2(std::ostringstream & out)
+static void fmt2([[maybe_unused]] std::ostringstream & out)
{
}
@@ -309,7 +309,7 @@ ElfFile<ElfFileParamNames>::ElfFile(FileContents fContents)
template<ElfFileParams>
-unsigned int ElfFile<ElfFileParamNames>::getPageSize() const
+unsigned int ElfFile<ElfFileParamNames>::getPageSize() const noexcept
{
if (forcedPageSize > 0)
return forcedPageSize;
@@ -555,7 +555,7 @@ std::optional<std::reference_wrapper<Elf_Shdr>> ElfFile<ElfFileParamNames>::tryF
template<ElfFileParams>
-unsigned int ElfFile<ElfFileParamNames>::getSectionIndex(const SectionName & sectionName)
+unsigned int ElfFile<ElfFileParamNames>::getSectionIndex(const SectionName & sectionName) const
{
for (unsigned int i = 1; i < rdi(hdr()->e_shnum); ++i)
if (getSectionName(shdrs.at(i)) == sectionName) return i;
diff --git a/src/patchelf.h b/src/patchelf.h
index 1308815..4857ab6 100644
--- a/src/patchelf.h
+++ b/src/patchelf.h
@@ -39,14 +39,14 @@ private:
/* Align on 4 or 8 bytes boundaries on 32- or 64-bit platforms
respectively. */
- size_t sectionAlignment = sizeof(Elf_Off);
+ static constexpr size_t sectionAlignment = sizeof(Elf_Off);
std::vector<SectionName> sectionsByOldIndex;
public:
explicit ElfFile(FileContents fileContents);
- bool isChanged()
+ [[nodiscard]] bool isChanged() const noexcept
{
return changed;
}
@@ -55,8 +55,8 @@ private:
struct CompPhdr
{
- ElfFile * elfFile;
- bool operator ()(const Elf_Phdr & x, const Elf_Phdr & y)
+ const ElfFile * elfFile;
+ bool operator ()(const Elf_Phdr & x, const Elf_Phdr & y) const noexcept
{
// A PHDR comes before everything else.
if (elfFile->rdi(y.p_type) == PT_PHDR) return false;
@@ -73,8 +73,8 @@ private:
struct CompShdr
{
- ElfFile * elfFile;
- bool operator ()(const Elf_Shdr & x, const Elf_Shdr & y)
+ const ElfFile * elfFile;
+ bool operator ()(const Elf_Shdr & x, const Elf_Shdr & y) const noexcept
{
return elfFile->rdi(x.sh_offset) < elfFile->rdi(y.sh_offset);
}
@@ -82,24 +82,24 @@ private:
friend struct CompShdr;
- unsigned int getPageSize() const;
+ [[nodiscard]] unsigned int getPageSize() const noexcept;
void sortShdrs();
void shiftFile(unsigned int extraPages, size_t sizeOffset, size_t extraBytes);
- std::string getSectionName(const Elf_Shdr & shdr) const;
+ [[nodiscard]] std::string getSectionName(const Elf_Shdr & shdr) const;
Elf_Shdr & findSectionHeader(const SectionName & sectionName);
- std::optional<std::reference_wrapper<Elf_Shdr>> tryFindSectionHeader(const SectionName & sectionName);
+ [[nodiscard]] std::optional<std::reference_wrapper<Elf_Shdr>> tryFindSectionHeader(const SectionName & sectionName);
- unsigned int getSectionIndex(const SectionName & sectionName);
+ [[nodiscard]] unsigned int getSectionIndex(const SectionName & sectionName) const;
std::string & replaceSection(const SectionName & sectionName,
unsigned int size);
- bool haveReplacedSection(const SectionName & sectionName) const;
+ [[nodiscard]] bool haveReplacedSection(const SectionName & sectionName) const;
void writeReplacedSections(Elf_Off & curOff,
Elf_Addr startAddr, Elf_Off startOffset);
@@ -116,7 +116,7 @@ public:
void rewriteSections(bool force = false);
- std::string getInterpreter();
+ [[nodiscard]] std::string getInterpreter();
typedef enum { printOsAbi, replaceOsAbi } osAbiMode;
@@ -158,21 +158,21 @@ private:
specified by the ELF header) to this platform's integer
representation. */
template<class I>
- I rdi(I i) const;
+ constexpr I rdi(I i) const noexcept;
/* Convert back to the ELF representation. */
template<class I>
- I wri(I & t, unsigned long long i) const
+ constexpr I wri(I & t, unsigned long long i) const
{
t = rdi((I) i);
return i;
}
- Elf_Ehdr *hdr() {
+ [[nodiscard]] Elf_Ehdr *hdr() noexcept {
return (Elf_Ehdr *)fileContents->data();
}
- const Elf_Ehdr *hdr() const {
+ [[nodiscard]] const Elf_Ehdr *hdr() const noexcept {
return (const Elf_Ehdr *)fileContents->data();
}
};