]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: avoid undefined behavior in qsort call
authorPádraig Brady <P@draigBrady.com>
Wed, 24 Jun 2015 18:14:47 +0000 (19:14 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 24 Jun 2015 18:15:31 +0000 (19:15 +0100)
GCC 5.1.1 -fsanitize=undefined with glibc 2.21 is returning:
"runtime error: null pointer passed as argument 1,
 which is declared to never be null"
* src/ptx.c (sort_found_occurs): Avoid the call with no entries.

src/ptx.c

index ff4e63a5fb33980b9cd1b567b017701af3d7a289..3aea4cdf2672c74c9e9d75310771144d9c6e525c 100644 (file)
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -631,9 +631,9 @@ sort_found_occurs (void)
 {
 
   /* Only one language for the time being.  */
-
-  qsort (occurs_table[0], number_of_occurs[0], sizeof **occurs_table,
-         compare_occurs);
+  if (number_of_occurs[0])
+    qsort (occurs_table[0], number_of_occurs[0], sizeof **occurs_table,
+           compare_occurs);
 }
 \f
 /* Parameter files reading routines.  */