From: Érico Rolim Date: Wed, 16 Dec 2020 22:30:12 +0000 (-0300) Subject: src/readelf: use qsort instead of qsort_r. X-Git-Tag: elfutils-0.183~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ad0758fddf1289077c43bbb125d0cd80c55aa72;p=thirdparty%2Felfutils.git src/readelf: use qsort instead of qsort_r. 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index 46f6c4ee6..5d0e384f0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2020-12-16 Érico Nogueira + + * readelf.c (qsort_r): Use qsort for improved portability. + 2020-12-20 Dmitry V. Levin * .gitignore: New file. diff --git a/src/readelf.c b/src/readelf.c index 829a418d2..0001a3d87 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