From: Timm Bäder Date: Fri, 8 Jan 2021 08:16:31 +0000 (+0100) Subject: readelf: Pull left() info file scope X-Git-Tag: elfutils-0.183~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=839880d243d1aa666aee3928c73d1c589c403a6f;p=thirdparty%2Felfutils.git readelf: Pull left() info file scope Get rid of a nested function this way. Signed-off-by: Timm Bäder --- diff --git a/src/ChangeLog b/src/ChangeLog index b12ea319e..4f395f1ef 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2021-01-08 Timm Bäder + + * readelf.c (print_attributes): Lift left function to... + (left): ...here. New file scope function taking Elf_Data and char + pointers. + 2021-01-08 Timm Bäder * readelf.c (handle_core_registers): Lift same_set function to... diff --git a/src/readelf.c b/src/readelf.c index 04ba4123d..dfc820ed9 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -3571,6 +3571,13 @@ print_liblist (Ebl *ebl) } } +static inline size_t +left (Elf_Data *data, + const unsigned char *p) +{ + return (const unsigned char *) data->d_buf + data->d_size - p; +} + static void print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr) { @@ -3615,13 +3622,8 @@ print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr) fputs_unlocked (_(" Owner Size\n"), stdout); - inline size_t left (void) - { - return (const unsigned char *) data->d_buf + data->d_size - p; - } - /* Loop over the sections. */ - while (left () >= 4) + while (left (data, p) >= 4) { /* Section length. */ uint32_t len; @@ -3630,7 +3632,7 @@ print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr) if (MY_ELFDATA != ehdr->e_ident[EI_DATA]) CONVERT (len); - if (unlikely (len > left ())) + if (unlikely (len > left (data, p))) break; /* Section vendor name. */