diff options
author | Dave Barach <dave@barachs.net> | 2020-04-24 16:07:37 -0400 |
---|---|---|
committer | Dave Barach <dave@barachs.net> | 2020-04-24 16:52:55 -0400 |
commit | f593b5792031b3797cdcdfd3fbb33ac4de8c9a5d (patch) | |
tree | 9168594df91cc649abf1691abd0d4f4bcfcdefbc /src/vppinfra/vec.h | |
parent | bf883bb086e22055c413f1e93bd11470620d5131 (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
Diffstat (limited to 'src/vppinfra/vec.h')
-rw-r--r-- | src/vppinfra/vec.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h index 9054eaa5e57..e9836107799 100644 --- a/src/vppinfra/vec.h +++ b/src/vppinfra/vec.h @@ -1040,12 +1040,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. |