From aaa6c3eacf2a3b9ea03d39f902d3cb97b9224190 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Fri, 8 Jan 2021 09:16:30 +0100 Subject: [PATCH] readelf: Pull same_set() info file scope MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Get rid of a nested function this way Signed-off-by: Timm Bäder --- src/ChangeLog | 6 ++++++ src/readelf.c | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 86dda4bc1..b12ea319e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2021-01-08 Timm Bäder + + * readelf.c (handle_core_registers): Lift same_set function to... + (same_set): ...here. New file scope function adding regs and + maxnreg arguments. + 2021-01-08 Timm Bäder * readelf.c (parse_opt): Lift add_dump_section function to... diff --git a/src/readelf.c b/src/readelf.c index 6233b2686..04ba4123d 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -12078,6 +12078,18 @@ compare_register_sets (const void *a, const void *b) return compare_sets_by_info (*p1, *p2); } +static inline bool +same_set (const struct register_info *a, + const struct register_info *b, + const struct register_info *regs, + size_t maxnreg) +{ + return (a < ®s[maxnreg] && a->regloc != NULL + && b < ®s[maxnreg] && b->regloc != NULL + && a->bits == b->bits + && (a->set == b->set || !strcmp (a->set, b->set))); +} + static unsigned int handle_core_registers (Ebl *ebl, Elf *core, const void *desc, const Ebl_Register_Location *reglocs, size_t nregloc) @@ -12116,19 +12128,12 @@ handle_core_registers (Ebl *ebl, Elf *core, const void *desc, qsort (regs, maxreg + 1, sizeof regs[0], &compare_registers); /* Collect the unique sets and sort them. */ - inline bool same_set (const struct register_info *a, - const struct register_info *b) - { - return (a < ®s[maxnreg] && a->regloc != NULL - && b < ®s[maxnreg] && b->regloc != NULL - && a->bits == b->bits - && (a->set == b->set || !strcmp (a->set, b->set))); - } struct register_info *sets[maxreg + 1]; sets[0] = ®s[0]; size_t nsets = 1; for (int i = 1; i <= maxreg; ++i) - if (regs[i].regloc != NULL && !same_set (®s[i], ®s[i - 1])) + if (regs[i].regloc != NULL + && !same_set (®s[i], ®s[i - 1], regs, maxnreg)) sets[nsets++] = ®s[i]; qsort (sets, nsets, sizeof sets[0], &compare_register_sets); @@ -12139,7 +12144,7 @@ handle_core_registers (Ebl *ebl, Elf *core, const void *desc, /* Find the longest name of a register in this set. */ size_t maxname = 0; const struct register_info *end; - for (end = sets[i]; same_set (sets[i], end); ++end) + for (end = sets[i]; same_set (sets[i], end, regs, maxnreg); ++end) { size_t len = strlen (end->name); if (len > maxname) -- 2.47.3