From: Timm Bäder Date: Fri, 8 Jan 2021 08:16:30 +0000 (+0100) Subject: readelf: Pull same_set() info file scope X-Git-Tag: elfutils-0.183~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aaa6c3eacf2a3b9ea03d39f902d3cb97b9224190;p=thirdparty%2Felfutils.git readelf: Pull same_set() 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 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)