[PATCH] readelf: Call qsort only if all_relocations_count != 0

H.J. Lu hjl.tools@gmail.com
Mon Sep 1 13:55:00 GMT 2025


Don't call qsort if all_relocations_count == 0.

	PR binutils/33351
	* readelf.c (process_got_section_contents): Call qsort only if
	all_relocations_count != 0.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 binutils/readelf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 2affc713adb..4915db928ba 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -21023,8 +21023,9 @@ process_got_section_contents (Filedata * filedata)
       goto out;
     }
 
-  qsort (all_relocations_root, all_relocations_count,
-	 sizeof (elf_relocation), elf_relocation_cmp);
+  if (all_relocations_count != 0)
+    qsort (all_relocations_root, all_relocations_count,
+	   sizeof (elf_relocation), elf_relocation_cmp);
 
   initialise_dumps_byname (filedata);
 
-- 
2.51.0



More information about the Binutils mailing list