commit:     3d813940e752cc3b9a230086013501d9453d2167
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Jan  3 22:15:39 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Jan  3 22:15:39 2016 +0000
URL:        https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=3d813940

paxelf: switch low level elf helpers to unsigned ints

Avoid using signed types when working with unsigned elf fields.

 paxelf.c | 28 +++++++++++++---------------
 paxelf.h |  6 +++---
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/paxelf.c b/paxelf.c
index b0ba144..ff385c5 100644
--- a/paxelf.c
+++ b/paxelf.c
@@ -15,11 +15,13 @@
 #define QUERY(n) { #n, n }
 typedef const struct {
        const char *str;
-       int value;
+       /* We use unsigned int as we assume it's at least 32 bits.  This covers
+          all our uses so far as they have been limited to that size.  */
+       unsigned int value;
 } pairtype;
-static inline const char *find_pairtype(pairtype *pt, int type)
+static inline const char *find_pairtype(pairtype *pt, unsigned int type)
 {
-       int i;
+       size_t i;
        for (i = 0; pt[i].str; ++i)
                if (type == pt[i].value)
                        return pt[i].str;
@@ -84,14 +86,12 @@ static pairtype elf_etypes[] = {
        { 0, 0 }
 };
 
-int get_etype(elfobj *elf)
+unsigned int get_etype(elfobj *elf)
 {
-       int type;
        if (elf->elf_class == ELFCLASS32)
-               type = EGET(EHDR32(elf->ehdr)->e_type);
+               return EGET(EHDR32(elf->ehdr)->e_type);
        else
-               type = EGET(EHDR64(elf->ehdr)->e_type);
-       return type;
+               return EGET(EHDR64(elf->ehdr)->e_type);
 }
 
 const char *get_elfetype(elfobj *elf)
@@ -162,10 +162,10 @@ void print_etypes(FILE *stream)
                fprintf(stream, "\n");
 }
 
-int etype_lookup(const char *str)
+unsigned int etype_lookup(const char *str)
 {
        if (*str == 'E') {
-               int i;
+               size_t i;
                for (i = 0; elf_etypes[i].str; ++i) {
                        if (strcmp(str, elf_etypes[i].str) == 0)
                                return elf_etypes[i].value;
@@ -275,14 +275,12 @@ static pairtype elf_emtypes[] = {
        { 0, 0 }
 };
 
-int get_emtype(elfobj *elf)
+unsigned int get_emtype(elfobj *elf)
 {
-       int type;
        if (elf->elf_class == ELFCLASS32)
-               type = EGET(EHDR32(elf->ehdr)->e_machine);
+               return EGET(EHDR32(elf->ehdr)->e_machine);
        else
-               type = EGET(EHDR64(elf->ehdr)->e_machine);
-       return type;
+               return EGET(EHDR64(elf->ehdr)->e_machine);
 }
 
 const char *get_elfemtype(elfobj *elf)

diff --git a/paxelf.h b/paxelf.h
index 034e0d7..4beec93 100644
--- a/paxelf.h
+++ b/paxelf.h
@@ -70,10 +70,10 @@ extern const char *get_elfstbtype(int type);
 extern const char *get_elfstvtype(int type);
 extern const char *get_elfstttype(int type);
 extern void *elf_findsecbyname(elfobj *elf, const char *name);
-extern int get_etype(elfobj *elf);
-extern int get_emtype(elfobj *elf);
+extern unsigned int get_etype(elfobj *elf);
+extern unsigned int get_emtype(elfobj *elf);
 extern void print_etypes(FILE *);
-extern int etype_lookup(const char *);
+extern unsigned int etype_lookup(const char *);
 
 /* PaX flags (to be read in elfhdr.e_flags) */
 #define HF_PAX_PAGEEXEC      1   /* 0: Paging based non-exec pages */

Reply via email to