aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Kardashevskiy <aik@ozlabs.ru>2021-01-27 19:33:49 +1100
committerAlexey Kardashevskiy <aik@ozlabs.ru>2021-02-12 13:41:47 +1100
commit26d8ba170355c951e53c08c357121d96bdb54076 (patch)
tree837809aefc4d61889aa803904585f4040ab2d4d4 /lib
parent0549fa7d08dc9865e25b2af1a46f8ccbe46fd312 (diff)
downloadSLOF-26d8ba170355c951e53c08c357121d96bdb54076.zip
SLOF-26d8ba170355c951e53c08c357121d96bdb54076.tar.gz
SLOF-26d8ba170355c951e53c08c357121d96bdb54076.tar.bz2
elf: Compile with -Wextra
-Wextra enables a bunch of rather useful checks which this fixes. This changes the return value for the case when no ELF headers were found to avoid (ugly-ish) cast of -1 to unsigned. Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> --- Changes: v2: * cast the return value to (int) * added missing (long)
Diffstat (limited to 'lib')
-rw-r--r--lib/libelf/elf.c2
-rw-r--r--lib/libelf/elf32.c6
-rw-r--r--lib/libelf/elf64.c8
3 files changed, 8 insertions, 8 deletions
diff --git a/lib/libelf/elf.c b/lib/libelf/elf.c
index d368454..f6a052e 100644
--- a/lib/libelf/elf.c
+++ b/lib/libelf/elf.c
@@ -202,7 +202,7 @@ elf_get_base_addr(void *file_addr)
* buffer larger than the size of the file
* @return The size of the ELF image or < 0 for error
*/
-long elf_get_file_size(const void *buffer, const long buffer_size)
+long elf_get_file_size(const void *buffer, const unsigned long buffer_size)
{
const struct ehdr *ehdr = (const struct ehdr *)buffer;
diff --git a/lib/libelf/elf32.c b/lib/libelf/elf32.c
index 64ea386..45b0015 100644
--- a/lib/libelf/elf32.c
+++ b/lib/libelf/elf32.c
@@ -212,13 +212,13 @@ elf_byteswap_header32(void *file_addr)
* file.
* @return Return -1 on error, size of file otherwise.
*/
-long elf_get_file_size32(const void *buffer, const long buffer_size)
+long elf_get_file_size32(const void *buffer, const unsigned long buffer_size)
{
const struct ehdr32 *ehdr = (const struct ehdr32 *) buffer;
const uint8_t *buffer_end = buffer + buffer_size;
const struct phdr32 *phdr;
const struct shdr32 *shdr;
- long elf_size = -1;
+ unsigned long elf_size = 0;
uint16_t entsize;
unsigned i;
@@ -258,5 +258,5 @@ long elf_get_file_size32(const void *buffer, const long buffer_size)
if (elf_size > buffer_size)
return -1;
- return elf_size;
+ return (long) elf_size;
}
diff --git a/lib/libelf/elf64.c b/lib/libelf/elf64.c
index 0f30267..3bc4040 100644
--- a/lib/libelf/elf64.c
+++ b/lib/libelf/elf64.c
@@ -389,7 +389,7 @@ elf_apply_all_rela64(void *file_addr, signed long offset, struct shdr64 *shdrs,
struct rela *relaentry;
struct sym64 *symtabentry;
uint32_t symbolidx;
- int i;
+ unsigned i;
/* If the referenced section has not been allocated, then it has
* not been loaded and thus does not need to be relocated. */
@@ -481,13 +481,13 @@ uint32_t elf_get_eflags_64(void *file_addr)
* file.
* @return Return -1 on error, size of file otherwise.
*/
-long elf_get_file_size64(const void *buffer, const long buffer_size)
+long elf_get_file_size64(const void *buffer, const unsigned long buffer_size)
{
const struct ehdr64 *ehdr = (const struct ehdr64 *) buffer;
const uint8_t *buffer_end = buffer + buffer_size;
const struct phdr64 *phdr;
const struct shdr64 *shdr;
- long elf_size = -1;
+ unsigned long elf_size = 0;
uint16_t entsize;
unsigned i;
@@ -527,5 +527,5 @@ long elf_get_file_size64(const void *buffer, const long buffer_size)
if (elf_size > buffer_size)
return -1;
- return elf_size;
+ return (long) elf_size;
}