]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
src/readelf: use qsort instead of qsort_r.
authorÉrico Rolim <erico.erc@gmail.com>
Wed, 16 Dec 2020 22:30:12 +0000 (19:30 -0300)
committerMark Wielaard <mark@klomp.org>
Sun, 10 Jan 2021 15:28:34 +0000 (16:28 +0100)
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.erc@gmail.com>
src/ChangeLog
src/readelf.c

index 46f6c4ee66aed0a969af0eb1046cda5e650f84e3..5d0e384f02ced70782a3ff4a1e603d94e0a6be01 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-16  Érico Nogueira  <ericonr@disroot.org>
+
+       * readelf.c (qsort_r): Use qsort for improved portability.
+
 2020-12-20  Dmitry V. Levin  <ldv@altlinux.org>
 
        * .gitignore: New file.
index 829a418d204830ad36a10cdceb1eb224886f70ca..0001a3d877dd694eccfb4fade8f6388b9a887720 100644 (file)
@@ -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