summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2020-04-24 16:07:37 -0400
committerAndrew Yourtchenko <ayourtch@gmail.com>2020-08-13 17:20:47 +0000
commit3b49dc6cc80e1a373363b2ff055327dda89e50db (patch)
tree8aba4de78be63336e5225abb9df5afc4b235f4d2
parenteaef2de7f92da67b6f47afdeac85d9d793d47470 (diff)
vppinfra: finish deprecating qsort.c
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)
-rw-r--r--extras/deprecated/vppinfra/qsort.c (renamed from src/vppinfra/qsort.c)0
-rw-r--r--src/vppinfra/vec.h10
2 files changed, 7 insertions, 3 deletions
diff --git a/src/vppinfra/qsort.c b/extras/deprecated/vppinfra/qsort.c
index 145ae40fe91..145ae40fe91 100644
--- a/src/vppinfra/qsort.c
+++ b/extras/deprecated/vppinfra/qsort.c
diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h
index 461c0de3347..da7d0896109 100644
--- a/src/vppinfra/vec.h
+++ b/src/vppinfra/vec.h
@@ -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.