vppinfra: finish deprecating qsort.c 09/28409/1
authorDave Barach <dave@barachs.net>
Fri, 24 Apr 2020 20:07:37 +0000 (16:07 -0400)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Thu, 13 Aug 2020 17:20:47 +0000 (17:20 +0000)
Minor change to vec_sort_with_function(...): don't depend on the qsort
implementation to deal with null, zero-long, or 1-long vectors

Type: fix

Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I7bd7b0421673d2a025363089562aa7c6266fba66
(cherry picked from commit f593b5792031b3797cdcdfd3fbb33ac4de8c9a5d)

extras/deprecated/vppinfra/qsort.c [moved from src/vppinfra/qsort.c with 100% similarity]
src/vppinfra/vec.h

index 461c0de..da7d089 100644 (file)
@@ -974,12 +974,16 @@ do {                                              \
 
 /** \brief Sort a vector using the supplied element comparison function
 
+    Does not depend on the underlying implementation to deal correctly
+    with null, zero-long, or 1-long vectors
+
     @param vec vector to sort
     @param f comparison function
 */
-#define vec_sort_with_function(vec,f)                          \
-do {                                                           \
-  qsort (vec, vec_len (vec), sizeof (vec[0]), (void *) (f));   \
+#define vec_sort_with_function(vec,f)                           \
+do {                                                            \
+  if (vec_len (vec) > 1)                                        \
+    qsort (vec, vec_len (vec), sizeof (vec[0]), (void *) (f));  \
 } while (0)
 
 /** \brief Make a vector containing a NULL terminated c-string.