From: Érico Rolim <erico....@gmail.com> This program is single threaded, so using qsort with a global variable isn't a danger. The interface for qsort_r isn't standardized (and diverges between glibc and FreeBSD, for example), which makes usage of qsort, where possible, preferrable.
Signed-off-by: Érico Rolim <erico....@gmail.com> --- Only difference from the initial patch is that this includes the Signed-off-by line. src/ChangeLog | 4 ++++ src/readelf.c | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2e428e0b..5c1ad1a2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2020-12-16 Érico Nogueira <eric...@disroot.org> + + * readelf.c (qsort_r): Use qsort for improved portability. + 2020-12-12 Mark Wielaard <m...@klomp.org> * elflint.c (check_sections): Handle SHF_GNU_RETAIN. diff --git a/src/readelf.c b/src/readelf.c index 829a418d..0001a3d8 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -4831,10 +4831,13 @@ listptr_base (struct listptr *p) return cudie_base (&cu); } +/* To store the name used in compare_listptr */ +static const char *sort_listptr_name; + static int -compare_listptr (const void *a, const void *b, void *arg) +compare_listptr (const void *a, const void *b) { - const char *name = arg; + const char *name = sort_listptr_name; struct listptr *p1 = (void *) a; struct listptr *p2 = (void *) b; @@ -4944,8 +4947,11 @@ static void sort_listptr (struct listptr_table *table, const char *name) { if (table->n > 0) - qsort_r (table->table, table->n, sizeof table->table[0], - &compare_listptr, (void *) name); + { + sort_listptr_name = name; + qsort (table->table, table->n, sizeof table->table[0], + &compare_listptr); + } } static bool -- 2.29.2